Esempio n. 1
0
func (this *AticleController) Del() {
	idstr := this.GetString("ids", "")
	if idstr == "" {
		this.ToJsonFails("id不能为空")
		return
	}
	var msg string = ""
	ids := strings.Split(idstr, ",")
	for _, i := range ids {
		id, err := strconv.Atoi(i)
		if err != nil {
			continue
		}
		_, err2 := utils.NewOrm().Delete(&models.Article{Id: id})
		if err2 == nil {
			msg = msg + strconv.Itoa(id) + " "
		}
	}
	if msg == "" {
		this.ToJsonFails("删除失败")
		return
	}
	this.ToJsonSuccess("成功删除Id:" + msg)

}
Esempio n. 2
0
func (this *TypeController) Add() {
	name := this.GetString("name", "")
	if name == "" {
		this.ToJsonFails("添加失败,请输入名称")
		return
	}
	_, err := utils.NewOrm().Insert(&models.Type{Name: name, Nums: 0})
	if err != nil {
		beego.Error(err)
		this.ToJsonFails("添加失败")
		return
	}
	this.ToJsonSuccess("添加成功")
}
Esempio n. 3
0
func (this *AticleController) Modify() {
	art := models.Article{}
	if err := this.ParseForm(&art); err != nil {
		beego.Error(err)

		return
	}
	beego.Info(art)
	if _, err := utils.NewOrm().Update(&art, "Title", "Content", "TypeId", "ModifyTime"); err != nil {
		types := models.GetAllType()
		models.GetByProperty(&art)
		this.Data["types"] = types
		this.Data["art"] = art
		this.Data["op"] = "modify"
		this.GetLayout("admin/edit.tpl")
		return
	}
	this.Manage()
}