/*
 * @description:标段-文件夹相关
 * @Author: CP
 * @Date: 2020-09-09 17:34:56
 * @FilePath: \construction_management\web\controllers\project_tree.go
 */
package controllers

import (
	"strconv"

	"go.mod/comm"
	"go.mod/web/utils"
)

// 标段-添加文件夹
func (c *ProjectController) PostBidsectionFolderAdd() {
	ErrMsg := ""
	// 验证内容
	FolderData, err := c.ServiceTree.ValidRule(c.Ctx)
	if err != nil {
		ErrMsg = utils.FormValidError(err)
		comm.Redirect(c.Ctx.ResponseWriter(), "/project/bidsection/manage?errMsg="+ErrMsg)
	} else {
		// 设置项目ID
		projectId, err := c.Ctx.Values().GetInt("projectId")
		if err != nil {
			comm.Redirect(c.Ctx.ResponseWriter(), "/project/bidsection/manage?errMsg=项目不存在")
		}
		FolderData.ProjectId = strconv.Itoa(projectId)
		// 新增文件夹
		err = c.ServiceTree.Create(FolderData)
		if err != nil {
			comm.Redirect(c.Ctx.ResponseWriter(), "/project/bidsection/manage?errMsg="+ErrMsg)
		}
		comm.Redirect(c.Ctx.ResponseWriter(), "/project/bidsection/manage?success=新增成功")
	}
}
