Exemplo n.º 1
0
 public ActionResult Label(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string sortData = "", int fid = 0)
 {
     //显示
     if (string.IsNullOrEmpty(act))
     {
         string filterSql             = $"state=1 and aid={aId} and storeid={storeId}";
         ViewModel <PinGoodsLabel> vm = new ViewModel <PinGoodsLabel>();
         vm.DataList   = PinGoodsLabelBLL.SingleModel.GetList(filterSql, pageSize, pageIndex, "*", "sort desc");
         vm.TotalCount = PinGoodsLabelBLL.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
             {
                 PinGoodsLabel updateModel = PinGoodsLabelBLL.SingleModel.GetModel(id);
                 if (updateModel != null)
                 {
                     updateModel.state = -1;
                     bool updateResult = PinGoodsLabelBLL.SingleModel.Update(updateModel);
                     if (updateResult)
                     {
                         result.code = 1;
                         result.msg  = "删除成功";
                     }
                     else
                     {
                         result.msg = "删除失败";
                     }
                 }
                 else
                 {
                     result.msg = "删除失败,对象不存在或已删除";
                 }
             }
         }
         else if (act == "sort")
         {
             bool updateResult = PinGoodsLabelBLL.SingleModel.UpdateSortBatch(sortData);
             result.code = updateResult ? 1 : 0;
             result.msg  = updateResult ? "排序成功" : "排序失败";
         }
     }
     return(Json(result));
 }
Exemplo n.º 2
0
 public ActionResult LabelEdit(string act = "", int id = 0, int aId = 0, int storeId = 0, PinGoodsLabel model = null, int fid = 0)
 {
     //参数验证
     if (id < 0 || aId <= 0 || storeId <= 0)
     {
         result.msg = "参数错误";
         return(Json(result));
     }
     //显示
     if (string.IsNullOrEmpty(act))
     {
         if (id == 0)
         {
             model = new PinGoodsLabel();
         }
         else
         {
             model = PinGoodsLabelBLL.SingleModel.GetModel(id);
             if (model == null)
             {
                 return(Content("对象不存在"));
             }
         }
         EditModel <PinGoodsLabel> em = new EditModel <PinGoodsLabel>();
         em.DataModel = model;
         em.aId       = aId;
         em.storeId   = storeId;
         return(View(em));
     }
     else
     {
         if (act == "edit")
         {
             if (!ModelState.IsValid)
             {
                 result.code = 0;
                 result.msg  = this.ErrorMsg();
                 return(Json(result));
             }
             if (id == 0)
             {
                 if (PinGoodsLabelBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and 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(PinGoodsLabelBLL.SingleModel.Add(model));
                 result.msg  = newid > 0 ? "添加成功" : "添加失败";
                 result.code = newid > 0 ? 1 : 0;
             }
             else
             {
                 if (PinGoodsLabelBLL.SingleModel.Exists($"state=1 and aid={aId} and storeid={storeId} and 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 = PinGoodsLabelBLL.SingleModel.Update(model, "name,sort");
                 result.msg  = updateResult ? "修改成功" : "修改失败";
                 result.code = updateResult ? 1 : 0;
             }
         }
     }
     return(Json(result));
 }