public ActionResult Attr(string act = "", int id = 0, int aId = 0, int storeId = 0, int fid = 0, int pageIndex = 0, int pageSize = 20, string sortData = "") { //显示 if (string.IsNullOrEmpty(act)) { string filterSql = $"state=1 and aid={aId} and storeid={storeId} and fid={fid}"; ViewModel <PinAttr> vm = new ViewModel <PinAttr>(); vm.DataList = PinAttrBLL.SingleModel.GetList(filterSql, pageSize, pageIndex, "*", "sort desc"); vm.TotalCount = PinAttrBLL.SingleModel.GetCount(filterSql); 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 { PinAttr updateModel = PinAttrBLL.SingleModel.GetModel(id); if (updateModel != null) { updateModel.state = -1; bool updateResult = PinAttrBLL.SingleModel.Update(updateModel); if (updateResult) { result.code = 1; result.msg = "删除成功"; } else { result.msg = "删除失败"; } } else { result.msg = "删除失败,对象不存在"; } } } else if (act == "sort") { bool updateResult = PinAttrBLL.SingleModel.UpdateSortBatch(sortData); result.code = updateResult ? 1 : 0; result.msg = updateResult ? "排序成功" : "排序失败"; } } return(Json(result)); }
/// <summary> /// 编辑规格和规格值 /// </summary> /// <returns></returns> public ActionResult AttrEdit(string act = "", int id = 0, int aId = 0, int storeId = 0, PinAttr model = null) { //参数验证 if (id < 0 || aId <= 0 || storeId <= 0) { result.msg = "参数错误"; return(Json(result)); } //显示 if (string.IsNullOrEmpty(act)) { if (id == 0) { model = new PinAttr(); } else { model = PinAttrBLL.SingleModel.GetModel(id); if (model == null) { return(Content("对象不存在")); } } EditModel <PinAttr> em = new EditModel <PinAttr>(); em.DataModel = model; em.aId = aId; em.storeId = storeId; return(View(em)); } else { if (!ModelState.IsValid) { result.code = 0; result.msg = this.ErrorMsg(); return(Json(result)); } if (act == "edit") { if (id == 0) { if (PinAttrBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and fid={model.fId} and BINARY name=@name", new MySql.Data.MySqlClient.MySqlParameter[] { new MySql.Data.MySqlClient.MySqlParameter("@name", model.name) })) { result.code = 0; result.msg = $"“{ model.name}” 已存在,不能重复添加!"; return(Json(result)); } int newid = Convert.ToInt32(PinAttrBLL.SingleModel.Add(model)); result.msg = newid > 0 ? "添加成功" : "添加失败"; result.code = newid > 0 ? 1 : 0; } else { if (PinAttrBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and fid={model.fId} and BINARY name=@name and id<>{id}", new MySql.Data.MySqlClient.MySqlParameter[] { new MySql.Data.MySqlClient.MySqlParameter("@name", model.name) })) { result.code = 0; result.msg = $"“{ model.name}” 已存在,不能重复添加!"; return(Json(result)); } bool updateResult = PinAttrBLL.SingleModel.Update(model, "name"); result.msg = updateResult ? "修改成功" : "修改失败"; result.code = updateResult ? 1 : 0; } } } return(Json(result)); }