示例#1
0
func (this *TopicController) Post() {
	if !checkAccount(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}

	tId := this.Input().Get("tid")
	title := this.Input().Get("title")
	content := this.Input().Get("content")
	category := this.Input().Get("cate")

	if "" != tId {
		err := models.ModifyTopic(tId, title, content)
		if err != nil {
			beego.Error(err)
			this.Redirect("/", 302)
			return
		}
	} else {
		err := models.AddTopic(title, content, category)
		if err != nil {
			beego.Error(err)
			this.Redirect("/", 302)
			return
		}
	}
	this.Redirect("/topic", 302)
}
示例#2
0
文件: topic.go 项目: ShinichR/myBlog
func (this *TopicController) Post() {
	if !checkAccount(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}
	tid := this.Input().Get("tid")
	title := this.Input().Get("title")
	content := this.Input().Get("content")
	label := this.Input().Get("label")
	category := this.Input().Get("category")

	if len(tid) != 0 {
		var err error
		beego.Debug("modify", title, content, label, category)
		err = models.ModifyTopic(tid, title, category, label, content)
		if err != nil {
			beego.Debug(err)
			this.Redirect("/topic", 302)
			return
		}
		this.Redirect("/topic", 302)

	} else {
		op := this.Input().Get("op")
		switch op {
		case "add":
			title := this.Input().Get("title")
			content := this.Input().Get("content")
			category := this.Input().Get("category")
			var err error
			err = models.AddTopic(title, category, label, content)
			if err != nil {
				return
			}
			this.Redirect("/topic", 302)
		case "del":
			id := this.Input().Get("id")
			if len(id) == 0 {
				break
			}

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

}