// @Title Update // @Description update the PmpMedia // @Param id path string true "The id you want to update" // @Param body body models.PmpMedia true "body for PmpMedia content" // @Success 200 {object} models.PmpMedia // @Failure 403 :id is not int // @router /:id [put] func (c *PmpMediaController) Put() { idStr := c.Ctx.Input.Params[":id"] id, _ := strconv.Atoi(idStr) v := models.PmpMedia{Id: id} json.Unmarshal(c.Ctx.Input.RequestBody, &v) if err := models.UpdatePmpMediaById(&v); err == nil { c.Data["json"] = "OK" } else { c.Data["json"] = err.Error() } c.ServeJson() }
// 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() }