Example #1
0
func (this *CategoryController) Delete() {
	categoryId := this.Ctx.Input.Param("0")
	err := models.DeleteCategory(categoryId)
	if err != nil {
		beego.Error(err)
		this.Redirect("/", 302)
		return
	}

	this.Redirect("/category", 302)
	return
}
Example #2
0
func (this *CategoryController) Get() {

	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", 302)
		return
	case "del":
		id := this.Input().Get("id")
		if len(id) == 0 {
			break
		}

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

	}

	this.Data["IsCategory"] = true
	this.TplName = "category.html"
	this.Data["IsLogin"] = checkAccount(this.Ctx)

	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}