示例#1
0
// @Title Post
// @Description create PmpMedia
// @Param	body		body 	models.PmpMedia	true		"body for PmpMedia content"
// @Success 200 {int} models.PmpMedia.Id
// @Failure 403 body is empty
// @router / [post]
func (c *PmpMediaController) Post() {
	var v models.PmpMedia
	//	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
	c.ParseForm(&v)
	if id, err := models.AddPmpMedia(&v); err == nil {
		c.Data["json"] = map[string]int64{"id": id}
	} else {
		c.Data["json"] = err.Error()
	}
	c.ServeJson()
}
示例#2
0
// save or update media
func (c *PmpMediaController) SaveOrUpdateMedia() {
	var v models.PmpMedia
	c.ParseForm(&v)
	beego.Info("*********** pased form values:", v)
	if v.Id == 0 {
		if id, err := models.AddPmpMedia(&v); err == nil {
			c.Data["json"] = map[string]int64{"id": id}
		} else {
			c.Data["json"] = err.Error()
		}
	} else {
		if err := models.UpdatePmpMediaById(&v); err == nil {
			c.Data["json"] = "OK"
		} else {
			c.Data["json"] = err.Error()
		}
	}
	c.ServeJson()
}