コード例 #1
0
ファイル: manage.go プロジェクト: lynndotconfig/go-blog
func (manage *ManageController) Update() {
	o := orm.NewOrm()
	o.Using("default")
	flash := beego.NewFlash()

	//convert the string value to an int
	if articleId, err := strconv.Atoi(manage.Ctx.Input.Param(":id")); err == nil {
		article := models.Article{Id: articleId}
		if o.Read(&article) == nil {
			article.Client = "Sitepoint"
			article.Url = "http:"
			if num, err := o.Update(&article); err == nil {
				flash.Notice("Record Was Update.")
				flash.Store(&manage.Controller)
				beego.Info("Record Was Update. ", num)
			} else {
				flash.Notice("Record Was NOT Updated.")
				flash.Store(&manage.Controller)
				beego.Error("Couldn't find article matching id: ", articleId)
			}
		} else {
			flash.Notice("Record Was NOT Updated.")
			flash.Store(&manage.Controller)
			beego.Error("Couldn't convert id from a string to a number. ", err)

		}
	}

	// redirect afterwards
	manage.Redirect("/manage/view", 302)

}