コード例 #1
0
ファイル: focuscate.go プロジェクト: blackmady/GoCMS
//添加分类
func (c FocusCate) Add(focusCate *models.FocusCate) revel.Result {

	if c.Request.Method == "GET" {

		title := "添加分类--GoCMS管理系统"

		c.Render(title)
		return c.RenderTemplate("Content/FocusCate/Add.html")

	} else {

		var name string = c.Params.Get("name")
		if len(name) > 0 {
			focusCate.Name = name
		} else {
			c.Flash.Error("请输入分类名称!")
			c.Flash.Out["url"] = "/focusCate/add/"
			return c.Redirect("/Message/")
		}

		var width string = c.Params.Get("width")
		if len(width) > 0 {
			Width, err := strconv.ParseInt(width, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focusCate.Width = Width
		} else {
			c.Flash.Error("请输宽度!")
			c.Flash.Out["url"] = "/focusCate/add/"
			return c.Redirect("/Message/")
		}

		var height string = c.Params.Get("height")
		if len(height) > 0 {
			Height, err := strconv.ParseInt(height, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focusCate.Height = Height
		} else {
			c.Flash.Error("请输入高度!")
			c.Flash.Out["url"] = "/focusCate/add/"
			return c.Redirect("/Message/")
		}

		if focusCate.Save() {
			c.Flash.Success("添加分类成功")
			c.Flash.Out["url"] = "/FocusCate/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加分类失败!")
			c.Flash.Out["url"] = "/FocusCate/add/"
			return c.Redirect("/Message/")
		}
	}
}