Esempio n. 1
0
func (this *CategoryController) Get() {
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	op := this.Input().Get("op")

	switch op {
	case "add":
		{
			name := this.Input().Get("name")
			if len(name) == 0 {
				break
			}
			err := models.AddCategory(name)
			if err != nil {
				beego.Error(err)
			}

			this.Redirect("/category", 301)
			return
		}
	case "del":
		{
			id := this.Input().Get("id")
			if len(id) == 0 {
				break
			}
			err := models.DelCategory(id)
			if err != nil {
				beego.Error(err)
			}

			this.Redirect("/category", 301)
			return
		}
	}
	this.Data["IsCategory"] = true
	this.TplName = "category.html"
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Esempio n. 2
0
func (c *CategoryController) Get() {

	c.Data["IsLogin"] = checkAccount(c.Ctx)

	op := c.Input().Get("op")
	switch op {
	case "add":
		name := c.Input().Get("name")
		if len(name) == 0 {
			break
		}
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 302)
	case "del":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}

		err := models.DelCategory(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 302)
	}

	c.Data["IsCategory"] = true
	c.TplNames = "category.html"

	var err error
	c.Data["Categories"], err = models.GetAllCategory()

	if err != nil {
		beego.Error(err)
	}
}