public JsonResult Add(DishStore store, int?attrTypeId, [System.Web.Http.FromBody] EditAttbute edit) { if (!attrTypeId.HasValue) { return(ApiModel(message: "参数不能为空[attrTypeId]")); } DishAttrType attrType = DishAttrTypeBLL.SingleModel.GetModel(attrTypeId.Value); if (attrType == null || attrType.storeId != store.id) { return(ApiModel(message: "非法操作")); } DishAttr newAttrbute = new DishAttr { attr_name = edit.Name, attr_values = string.Join("\n", edit.Option), aid = store.aid, cat_id = edit.AttrTypeId, storeId = store.id, sort = edit.Sort, state = 1, }; int newId; bool success = int.TryParse(DishAttrBLL.SingleModel.Add(newAttrbute)?.ToString(), out newId) && newId > 0; return(ApiModel(isok: success, message: success ? "新增成功" : "新增失败")); }
public JsonResult Edit(DishStore store, int?attrbuteId, [System.Web.Http.FromBody] EditAttbute edit) { if (!attrbuteId.HasValue) { return(ApiModel(message: "参数不能为空[attrbuteId]")); } DishAttr attrbute = DishAttrBLL.SingleModel.GetModel(attrbuteId.Value); if (attrbute == null || attrbute.storeId != store.id) { return(ApiModel(message: "非法操作")); } attrbute.attr_name = edit.Name; attrbute.cat_id = edit.AttrTypeId; attrbute.attr_values = string.Join("\n", edit.Option); attrbute.sort = edit.Sort; bool success = DishAttrBLL.SingleModel.Update(attrbute, "cat_id,attr_name,sort,attr_values"); return(ApiModel(isok: success, message: success ? "编辑成功" : "编辑失败")); }