func (c *ArticleController) CreateArticle() {

	user := c.GetSession("user")
	if nil == user {
		c.Redirect("/users/login", 200)
	}

	userId := c.CurrentUserId()
	content := c.GetString("content")
	title := c.GetString("title")
	tag := c.GetString("tag")
	categories := c.GetString("category")

	beego.Debug("title", title, "categories", categories, "tag", tag, "content", content)

	article := entities.Article{UserId: userId, Title: title, Content: content, CreatedAt: time.Now()}
	err, valid := services.ValidArticle(article)
	if valid {
		prt := &article
		prt.SetCategories(categories)
		prt.SetTags(tag)
		err = services.SaveArticle(&article)
	}

	if nil == err {
		c.Redirect("../", 302)
	} else {
		beego.Error(err)
		c.StringError(err.Error())
		c.Data["article"] = article
		c.SetCategories(article.UserId)
		c.TplName = "article_create.html"
	}

}
func (c *ArticleController) UpdateArticle() {

	user := c.CurrentUser()
	if nil == user {
		c.Redirect("/users/login", 200)
	}

	id, err := c.GetInt64("id")
	beego.Error("id:", id)

	var article entities.Article
	if nil == err {
		userId := c.CurrentUserId()
		content := c.GetString("content")
		title := c.GetString("title")
		tag := c.GetString("tag")
		categories := c.GetString("category")
		beego.Error("tag", tag, "categories", categories)
		article = entities.Article{Id: id, UserId: userId, Title: title, Content: content, CreatedAt: time.Now()}
		prt := &article
		prt.SetCategories(categories)
		prt.SetTags(tag)
		beego.Error("tag", article.Tags, "categories", article.Categories)
		exception, valid := services.ValidArticle(article)
		if valid {
			err = services.UpdateArticle(&article)
		} else {
			err = exception
		}

	}

	if nil == err {
		c.Redirect("../", 302)
	} else {
		beego.Error(err)
		c.StringError(err.Error())
		c.Data["article"] = article
		c.TplName = "article_create.html"
		c.SetCategories(user.Id)

	}
}