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 ? "新增成功" : "新增失败")); }
/// <summary> /// 编辑属性类型 /// </summary> /// <returns></returns> public ActionResult Edit(string act = "", int id = 0, int aId = 0, int storeId = 0, DishAttrType model = null) { //参数验证 if (id < 0 || aId <= 0 || storeId <= 0) { _result.msg = "参数错误"; return(Json(_result)); } //显示 if (string.IsNullOrEmpty(act)) { if (id == 0) { model = new DishAttrType(); } else { model = DishAttrTypeBLL.SingleModel.GetModel(id); if (model == null) { return(Content("分类不存在")); } } EditModel <DishAttrType> em = new EditModel <DishAttrType>(); em.DataModel = model; em.aId = aId; em.storeId = storeId; return(View(em)); } else { if (act == "edit") { if (id == 0) { int newid = Convert.ToInt32(DishAttrTypeBLL.SingleModel.Add(model)); _result.msg = newid > 0 ? "添加成功" : "添加失败"; _result.code = newid > 0 ? 1 : 0; } else { bool updateResult = DishAttrTypeBLL.SingleModel.Update(model); _result.msg = updateResult ? "修改成功" : "修改失败"; _result.code = updateResult ? 1 : 0; } } } return(Json(_result)); }
/// <summary> /// 属性类型管理 /// </summary> /// <returns></returns> public ActionResult Index(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string sortData = "") { //显示 if (string.IsNullOrEmpty(act)) { ViewModel <DishAttrType> vm = new ViewModel <DishAttrType>(); vm.DataList = DishAttrTypeBLL.SingleModel.GetListFromTable(pageIndex, pageSize, aId, storeId); vm.TotalCount = DishAttrTypeBLL.SingleModel.GetCount($"state<>-1 and aid={aId} and storeid={storeId}"); vm.PageIndex = pageIndex; vm.PageSize = pageSize; vm.aId = aId; vm.storeId = storeId; return(View(vm)); } else { //删除 if (act == "del") { if (id <= 0) { _result.msg = "参数错误"; } else { DishAttrType updateModel = DishAttrTypeBLL.SingleModel.GetModel(id); if (updateModel != null) { updateModel.state = -1; bool updateResult = DishAttrTypeBLL.SingleModel.Update(updateModel); if (updateResult) { _result.code = 1; _result.msg = "删除成功"; } else { _result.msg = "删除失败"; } } else { _result.msg = "删除失败,分类不存在"; } } } } return(Json(_result)); }
public JsonResult AddType(DishStore store, [System.Web.Http.FromBody] EditAttrType edit) { DishAttrType newAttrType = new DishAttrType { aid = store.aid, cat_name = edit.Name, enabled = edit.Enable.Value ? 1 : 0, storeId = store.id, state = 1, }; int newId; bool success = int.TryParse(DishAttrTypeBLL.SingleModel.Add(newAttrType)?.ToString(), out newId) && newId > 0; return(ApiModel(isok: success, message: success ? "新增成功" : "新增失败")); }
public JsonResult DeleteType(DishStore store, int?attrTypeId) { if (!attrTypeId.HasValue) { return(ApiModel(message: "参数不能为空[attrTypeId]")); } DishAttrType attrType = DishAttrTypeBLL.SingleModel.GetModel(attrTypeId.Value); if (attrType == null || attrType.storeId != store.id) { return(ApiModel(message: "非法操作")); } bool success = DishAttrTypeBLL.SingleModel.DeleteAttrType(attrType); return(ApiModel(isok: success, message: success ? "删除成功" : "删除失败")); }
public JsonResult EditType(DishStore store, int?attrTypeId, [System.Web.Http.FromBody] EditAttrType 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: "非法操作")); } attrType.enabled = edit.Enable.Value ? 1 : 0; attrType.cat_name = edit.Name; bool success = DishAttrTypeBLL.SingleModel.Update(attrType, "enabled,cat_name"); return(ApiModel(isok: success, message: success ? "编辑成功" : "编辑失败")); }