示例#1
0
func (a *SponsorAction) Put() {
	vars, ok := a.Ctx.Params["id"]
	var id int
	var err error = nil
	if ok {
		id, err = strconv.Atoi(vars)
	}

	if (err == nil) && ok {

		a.Ctx.Request().ParseForm()
		dec := json.NewDecoder(a.Ctx.Request().Body)

		var m map[string]interface{}
		dec.Decode(&m)

		sup := models.Sponsor{}

		a.Ctx.DB.Where("id = ?", id).Find(&sup)

		sup.Name, _ = m["name"].(string)
		sup.Note, _ = m["note"].(string)
		px, _ := m["phone"].(string)
		pxt, _ := strconv.Atoi(px)
		sup.PhoneExt = uint(pxt)

		a.Ctx.DB.Save(&sup)

		a.RenderJSON(sup, http.StatusOK)
	}
}
示例#2
0
func (a *SponsorAction) Post() {
	a.Ctx.Request().ParseForm()
	dec := json.NewDecoder(a.Ctx.Request().Body)

	var m map[string]interface{}
	dec.Decode(&m)

	sup := new(models.Sponsor)
	sup.Name, _ = m["name"].(string)
	sup.Note, _ = m["note"].(string)
	px, _ := m["phone"].(string)
	pxt, _ := strconv.Atoi(px)
	sup.PhoneExt = uint(pxt)

	a.Ctx.DB.Create(&sup)

	a.RenderJSON(sup, http.StatusOK)
}