Beispiel #1
0
func (c *CategoryController) Get() {
	op := c.Input().Get("op")
	switch op {
	case "add":
		category := c.Input().Get("category")
		if len(category) == 0 {
			break
		}
		err := models.AddCategory(category)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
		return

	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", 301)
	}

	c.Data["IsCategory"] = true
	c.TplNames = "category.html"
	var err error
	c.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Beispiel #2
0
func (this *TopicController) Post() {
	if !checkAccount(this.Ctx) {
		this.Redirect("/login", 302)
	}
	/* 解析表单 */
	title := this.Input().Get("title")
	category := this.Input().Get("category")
	content := this.Input().Get("content")
	tid := this.Input().Get("tid")

	var err error

	if len(tid) == 0 {
		err = models.AddTopic(title, content, category)
		if models.CheckCategory(category) {
			beego.Debug("had")
			models.UpdateCategory(category)
		} else {
			beego.Debug("Not ! ")
			models.AddCategory(category)
		}
	} else {
		err = models.ModifyTopic(tid, title, content, category)
		if models.CheckCategory(category) {
			beego.Debug("had")
		} else {
			beego.Debug("Not ! ")
			models.AddCategory(category)
		}
	}
	if err != nil {
		beego.Error(err)
	}

	this.Redirect("/topic", 302)
}
Beispiel #3
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", 301)
		return
	case "del":
		println("ssssssss....................")

		id := this.Input().Get("id")
		if len(id) == 0 {
			break
		}

		println(".......category 1")

		err := models.DelCategory(id)

		println(".......category 2")

		if err != nil {
			beego.Error(err)
		}
		println(".......category 3")
		this.Redirect("/category", 301)
		return
	}

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

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

	if err != nil {
		beego.Error(err)
	}
}
Beispiel #4
0
func (this *CategoryController) Get() {
	this.Data["IsCategory"] = true

	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.TplNames = "category.html"

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

	switch op {
	case "add":
		name := this.Input().Get("category")
		beego.Debug(name)
		if len(name) == 0 {
			break
		}
		/* 需要在models 里面处理 */
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
		this.Redirect("/category", 302)
		return

	case "del":
		id := this.Input().Get("id")
		beego.Debug(id)
		if len(id) == 0 {
			break
		}

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

	/* 取值分类中的所以列 Categories 在页面中*/
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Beispiel #5
0
func (this *CategoryController) Get() {
	this.Data["IsCategory"] = true
	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
	}

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

	if err != nil {
		beego.Error(err)
	}
}
Beispiel #6
0
func (this *CategoryController) Get() {
	op := this.Input().Get("op")
	name := this.Input().Get("name")
	fmt.Println("op value:" + op + " name value:" + name)
	switch op {
	case "add":
		fmt.Println("categoryADD")
		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":
		fmt.Println("categoryDEL")
		id := this.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.DelCategories(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)
	}
}
Beispiel #7
0
func (c *CategroyController) Get() {

	op := c.Input().Get("op")
	switch op {
	case "add":
		cname := c.Input().Get("cname")
		if len(cname) == 0 {
			break
		}
		err := models.AddCategory(cname)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
		return
	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", 301)
		return
	default:
		c.Data["IsLogin"] = checkAccount(c.Ctx)
		c.Data["IsCategray"] = true
		c.TplNames = "categroy.html"
		var err error
		c.Data["Categories"], err = models.GetAllCategories()
		if err != nil {
			beego.Error(nil)
		}
	}

}