Beispiel #1
0
func (this *CategoryController) Add() {
	categotyName := this.Input().Get("category")
	err := models.AddCategory(categotyName)
	if err != nil {
		beego.Error(err)
		this.Redirect("/", 302)
		return
	}
	this.Redirect("/category", 302)
	return
}
Beispiel #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)
	}
}
Beispiel #3
0
func (this *AdminCategoryController) Get() {

	if isSignIn, admin := CheckAccount(this.Ctx); isSignIn {

		op := this.Input().Get("op")

		switch op {

		case "add":

			title := this.Input().Get("title")

			if len(title) == 0 {
				break
			}

			err := models.AddCategory(title)

			if err != nil {

				beego.Error(err)
			}

			this.Redirect("./admincategory", 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("./admincategory", 301)
			return
		}

		this.Data["PageTitle"] = "CategoryManager"
		this.Data["Admin"] = admin
		this.Data["IsCategory"] = true

		var err error
		this.Data["Categories"], err = models.GetAllCategories()

		if err != nil {

			beego.Error(err)
		}

		this.Layout = "layout/admin_layout.tpl"
		this.TplNames = "admin_category/index.tpl"
	} else {

		this.Redirect("/adminlogin", 301)
		return
	}
}