Beispiel #1
0
func (c *Admin) NewCategoryPost(category models.Category) revel.Result {
	category.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Admin.NewCategory())
	}

	if !category.Save() {
		c.Flash.Error("添加分类失败")
	}

	return c.Redirect(routes.Admin.ListCategory())
}
Beispiel #2
0
func (c *Admin) EditCategory(id int64) revel.Result {
	title := "编辑分类"

	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	category := new(models.Category)
	category.Id = id
	q.Find(category)

	c.Render(title, category)

	return c.RenderTemplate("Admin/NewCategory.html")
}
Beispiel #3
0
func (c *Admin) DeleteCategory(id int64) revel.Result {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	category := new(models.Category)
	category.Id = id
	q.Find(category)

	_, err = q.Delete(category)
	if err != nil {
		fmt.Println(err)
	}

	return c.RenderJson([]byte("true"))
}