예제 #1
0
파일: user.go 프로젝트: Joinhack/fragement
//@Mapper("/admin/user/save")
func (u *User) Save(user *model.User, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*User).Add
	if opType == "edit" {
		back = (*User).Edit
	}
	if len(user.LoginId) == 0 {
		flash.Error("登录ID不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if len(user.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if len(user.Password) < 6 {
		flash.Error("密码长度不够")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if opType == "edit" {
		flash.Success(user.LoginId + "修改成功")
		engine.Id(user.Id).AllCols().Update(user)
	} else {
		flash.Success(user.LoginId + "添加成功")
		engine.Insert(user)
	}
	return peony.Redirect((*User).Users)
}
예제 #2
0
//@Mapper("/admin/vendor/save")
func (v *Vendor) Save(vendor *model.Vendor, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Vendor).Add
	if opType == "edit" {
		back = (*Vendor).Edit
	}
	if len(vendor.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": vendor.Id})
	}
	if vendor.VendorId == 0 {
		flash.Error("VendorId不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": vendor.Id})
	}

	if opType == "edit" {
		flash.Success(vendor.Name + "修改成功")
		engine.Id(vendor.Id).AllCols().Update(vendor)
	} else {
		flash.Success(vendor.Name + "添加成功")
		engine.Insert(vendor)
	}
	return peony.Redirect((*Vendor).Vendors)
}
예제 #3
0
//@Mapper("/admin/nas/save")
func (v *Nas) Save(nas *model.Nas, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Nas).Add
	if opType == "edit" {
		back = (*Nas).Edit
	}
	if len(nas.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": nas.Id})
	}
	if len(nas.Ip) == 0 {
		flash.Error("IP不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": nas.Id})
	}

	if opType == "edit" {
		flash.Success(nas.Ip + "修改成功")
		engine.Id(nas.Id).AllCols().Update(nas)
	} else {
		flash.Success(nas.Ip + "添加成功")
		engine.Insert(nas)
	}
	return peony.Redirect((*Nas).Nass)
}
예제 #4
0
//@Mapper("/admin/attr/save")
func (v *Attr) Save(attr *model.Attr, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Attr).Add
	if opType == "edit" {
		back = (*Attr).Edit
	}
	if len(attr.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": attr.Id})
	}
	if attr.Type == 0 {
		flash.Error("类型不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": attr.Id})
	}

	if opType == "edit" {
		flash.Success(attr.Name + "修改成功")
		engine.Id(attr.Id).AllCols().Update(attr)
	} else {
		flash.Success(attr.Name + "添加成功")
		engine.Insert(attr)
	}
	return peony.Redirect((*Attr).Attrs)
}
예제 #5
0
//@Mapper("/admin/vendor/<id>/del")
func (u *Vendor) Del(id int64, flash *peony.Flash) peony.Renderer {
	var vendor = &model.Vendor{}
	engine.Id(id).Delete(vendor)
	flash.Success(fmt.Sprintf("厂商:%s 删除成功~!", vendor.Name))
	return peony.Redirect((*Vendor).Vendors)
}
예제 #6
0
//@Mapper("/admin/nas/<id>/del")
func (u *Nas) Del(id int64, flash *peony.Flash) peony.Renderer {
	var nas = &model.Nas{}
	engine.Id(id).Delete(nas)
	flash.Success(fmt.Sprintf("Nas:%s 删除成功~!", nas.Name))
	return peony.Redirect((*Nas).Nass)
}
예제 #7
0
//@Mapper("/admin/attr/<id>/del")
func (u *Attr) Del(id int64, flash *peony.Flash) peony.Renderer {
	var attr = &model.Attr{}
	engine.Id(id).Delete(attr)
	flash.Success(fmt.Sprintf("属性:%s 删除成功~!", attr.Name))
	return peony.Redirect((*Attr).Attrs)
}
예제 #8
0
파일: user.go 프로젝트: Joinhack/fragement
//@Mapper("/admin/user/<id>/del")
func (u *User) Del(id int64, flash *peony.Flash) peony.Renderer {
	var user = &model.User{}
	engine.Id(id).Delete(user)
	flash.Success(fmt.Sprintf("帐号:%s 删除成功~!", user.LoginId))
	return peony.Redirect((*User).Users)
}