Example #1
0
//delete
func (this *ArticleController) Delete() {
	var (
		id      int64
		article models.Article
	)

	id, _ = this.GetInt64("id")
	article.Id = id

	if err := article.Read(); err == nil {
		fmt.Println(err)
	}

	article.Status = 2
	article.Update("status")

	tag := models.Tag{Name: article.Tag}
	tag.Read("Name")
	tag.Count--
	tag.Update("count")

	this.Redirect(this.Ctx.Request.Referer(), 302)
}
Example #2
0
//保存
func (this *ArticleController) Save() {
	var (
		id          int64  = 0
		title       string = strings.TrimSpace(this.GetString("title"))
		content     string = this.GetString("content")
		status      int    = 0
		happenMonth string = strings.TrimSpace(this.GetString("happenMonth"))
		happenDay   string = strings.TrimSpace(this.GetString("happenDay"))
		article     models.Article
		tag         models.Tag
	)

	if title == "" {
		this.showmsg("标题不能为空!")
	}

	id, _ = this.GetInt64("id")
	status, _ = this.GetInt("status")

	tagName := this.GetString("tag")
	fmt.Println(tagName)
	tag.Name = tagName
	tag.Read("name")

	if status != 1 {
		status = 0
	}

	if id < 1 {
		article.AuthorId = this.userid
		article.AuthorName = this.username
		article.Tag = tagName
		err := article.Insert()
		if err != nil {
			fmt.Println(err)
		}

		tag.Count = tag.Count + 1
		tag.Update()
	} else {
		article.Id = id
		if article.Read() != nil {
			goto RD
		}
	}

	if article.Tag != tagName {
		desTag := models.Tag{Name: article.Tag}
		desTag.Read("name")
		desTag.Count--
		desTag.Update("count")

		tag.Count = tag.Count + 1
		tag.Update()

		article.Tag = tagName
	}

	article.Status = status
	article.Title = title
	article.Content = content
	article.HappenMonth = happenMonth
	article.HappenDay = happenDay
	article.Update("tag", "status", "title", "content", "happen_month", "happen_day")

RD:
	url := "/admin/article/list?t=date&m=" + happenMonth + "&d=" + happenDay
	this.Redirect(url, 302)
}