Пример #1
0
//添加分类
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/")
		}
	}
}
Пример #2
0
//编辑分类
func (c FocusCate) Edit(focusCate *models.FocusCate) revel.Result {

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

		title := "编辑分类--GoCMS管理系统"

		var id string = c.Params.Get("id")

		if len(id) > 0 {
			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			focusCate_info := focusCate.GetById(Id)

			c.Render(title, focusCate_info)
		} else {
			c.Render(title)
		}

		return c.RenderTemplate("Content/FocusCate/Edit.html")

	} else {

		var id string = c.Params.Get("id")

		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		var name string = c.Params.Get("name")
		if len(name) > 0 {
			focusCate.Name = name
		} else {
			c.Flash.Error("请输入分类名称!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			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/edit/" + id + "/"
			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/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

		if focusCate.Edit(Id) {
			c.Flash.Success("编辑分类成功")
			c.Flash.Out["url"] = "/FocusCate/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("编辑分类失败!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

	}
}