public bool IsValidSpikeProduct(DateTime dateTime, int Id, out string msg) { msg = ""; List <SWfsSubjectSpikeProductManage> list = DapperUtil.Query <SWfsSubjectSpikeProductManage>("ComBeziWfs_SWfsSubjectSpikeProductManage_IsValidSpikeProduct", new { ShowTime = dateTime }).ToList(); var model = list.Where(r => r.ShowTime.Equals(dateTime)).FirstOrDefault(); if (Id == 0) //添加时判断数量和时间是否存在 { if (model != null) //存在一个相同时间段的商品,或则该天内添加的商品个数大于3个,均不能再添加了 { msg = "该时间段已有商品"; return(true); } if (list.Count >= 3) { msg = "每组添加的商品个数不能大于3个"; return(true); } else { return(false); } } else //修改时,只判断时间 { SWfsSubjectSpikeProductManage oldModel = GetSWfsSubjectSpikeProductManage(Id.ToString()); if (oldModel == null) { msg = "修改秒杀商品不存在"; return(true); } if (oldModel.ShowTime.Year == dateTime.Year && oldModel.ShowTime.Month == dateTime.Month && oldModel.ShowTime.Day == dateTime.Day) { if (model != null && !model.ID.Equals(Id)) //表示修改的日期组与已有的相同 { msg = "该时间段已有商品"; return(true); } } else //修改到其他组 { if (list.Count >= 3) { msg = "每组添加的商品个数不能大于3个"; return(true); } } } //var t = DapperUtil.Query<int>("ComBeziWfs_SWfsSubjectSpikeProductManage_IsValidSpikeProduct", new { ShowTime = dateTime }).FirstOrDefault(); //if (t > 0) //{ // return true; //} return(false); }
public ActionResult SpikeProduct() { //act=edit&Id=1 string Id = Request.QueryString["Id"]; string act = Request.QueryString["act"]; SWfsSubjectSpikeProductManage model = null; if (!string.IsNullOrEmpty(Id) && !string.IsNullOrEmpty(act) && act.Equals("edit")) { SWfsChannelService channelService = new SWfsChannelService(); model = channelService.GetSWfsSubjectSpikeProductManage(Id); } return(View(model)); }
public void UpdateSWfsSubjectSpikeProduct(SWfsSubjectSpikeProductManage model) { DapperUtil.Update <SWfsSubjectSpikeProductManage>(model); }
public void AddSWfsSubjectSpikeProduct(SWfsSubjectSpikeProductManage model) { DapperUtil.Insert <SWfsSubjectSpikeProductManage>(model); }
public ActionResult AddSpikeProduct(SWfsSubjectSpikeProductManage model) { //if (string.IsNullOrWhiteSpace(model.ProductNo)) //{ // return Json(new { reslut = false, msg = "请选择秒杀商品" }); //} //if (model.ShowTime == null) //{ // return Json(new { reslut = false, msg = "请选择展示日期" }); //} //增加逻辑判断,如果存在同一时段的秒杀商品,则不能添加成功 SWfsChannelService service = new SWfsChannelService(); string tmpMsg = string.Empty; if (service.IsValidSpikeProduct(model.ShowTime, model.ID, out tmpMsg)) { return(Json(new { reslut = false, msg = tmpMsg })); } if (null != Request.Files["ShowProductPicFileNo"] && Request.Files["ShowProductPicFileNo"].ContentLength > 0) { CommonService commonService = new CommonService(); Dictionary <string, string> rsPic = commonService.PostImg(Request.Files["ShowProductPicFileNo"], "width:300,Height:620,Length:150"); if (rsPic.Keys.Contains("error")) { return(Json(new { reslut = false, msg = rsPic["error"] })); } if (rsPic.Keys.Contains("success")) { model.ShowProductPicFileNo = rsPic["success"]; } } else { if (!model.ID.Equals(0)) //修改没有上传图片 则 { model.ShowProductPicFileNo = Request.Form["ESPPicFileNo"]; } else { return(Json(new { reslut = false, msg = "请上传展示图片" })); } } model.Status = (short)1; //暂时没用上,备用始终为1 if (model.ID.Equals(0)) //新增 { model.DateCreate = DateTime.Now; model.CreateUserId = PresentationHelper.GetPassport().UserName; try { service.AddSWfsSubjectSpikeProduct(model); return(Json(new { reslut = true, msg = "添加成功" })); } catch (Exception) { return(Json(new { reslut = false, msg = "添加失败" })); } } else //修改 { if (string.IsNullOrWhiteSpace(model.ProductNo)) { model.Type = 1; } else { model.Type = 0; } try { service.UpdateSWfsSubjectSpikeProduct(model); return(Json(new { reslut = true, msg = "修改成功" })); } catch (Exception) { return(Json(new { reslut = false, msg = "修改失败" })); } } }