Beispiel #1
0
func (c Admin) EditCategoryPost(id int64, category models.Category) revel.Result {
	category.Id = id
	category.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Admin.EditCategory(id))
	}

	aff, _ := c.Engine.Id(id).Update(&category)
	if aff > 0 {
		c.Flash.Success("编辑分类成功")
		cache.Flush()
	} else {
		c.Flash.Error("编辑分类失败")
		return c.Redirect(routes.Admin.EditCategory(id))
	}

	return c.Redirect(routes.Admin.ListCategory())
}
Beispiel #2
0
func (c Topic) EditPost(id int64, topic models.Topic, category int64) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.Edit(id))
	}

	topic.Category = models.Category{Id: category}

	aff, _ := c.Engine.Id(id).Cols("title", "category_id", "content").Update(&topic)
	if aff > 0 {
		c.Flash.Success("编辑帖子成功")
		cache.Flush()
	} else {
		c.Flash.Error("编辑帖子失败")
	}

	return c.Redirect(routes.Topic.Show(id))
}
Beispiel #3
0
func (c Topic) NewPost(topic models.Topic, category int64) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.New())
	}

	topic.User = models.User{Id: c.user().Id}
	topic.Category = models.Category{Id: category}

	aff, _ := c.Engine.Insert(&topic)
	if aff > 0 {
		c.Flash.Success("发表新帖成功")
		cache.Flush()
	} else {
		c.Flash.Error("发表新帖失败")
	}

	return c.Redirect(routes.Topic.Index(1))
}
Beispiel #4
0
// 回复帖子
func (c Topic) Reply(id int64, content string) revel.Result {
	c.Validation.Required(content).Message("请填写回复内容")
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.Show(id))
	}

	aff, _ := c.Engine.Insert(&models.Reply{
		Topic:   models.Topic{Id: id},
		User:    models.User{Id: c.user().Id},
		Content: content,
	})

	if aff > 0 {
		c.Engine.Exec("UPDATE topic SET replies = replies + 1 WHERE id = ?", id)
		cache.Flush()
	} else {
		c.Flash.Error("发表回复失败")
	}

	return c.Redirect(routes.Topic.Show(id))
}