public void CancelCollocation(long CollocationId, long shopId) { CollocationInfo date = context.CollocationInfo.FirstOrDefault((CollocationInfo a) => a.Id == CollocationId && a.ShopId == shopId); if (date != null) { date.EndTime = DateTime.Now.Date; } context.SaveChanges(); }
public void AddCollocation(Collocation info) { CheckCollocationDate(info.ShopId, info.EndTime); var date = DateTime.Now.Date; var mainId = info.Products.Where(a => a.IsMain == true).Select(a => a.ProductId).FirstOrDefault(); var flag = DbFactory.Default .Get <CollocationPoruductInfo>() .InnerJoin <CollocationInfo>((cpi, ci) => ci.Id == cpi.ColloId) .Where(a => a.IsMain == true && a.ProductId == mainId) .Where <CollocationInfo>(a => a.EndTime > date) .Exist(); if (flag) { throw new MallException("此主商品已存在组合购,请勿重复添加!"); } DbFactory.Default .InTransaction(() => { var model = new CollocationInfo { Title = info.Title, StartTime = info.StartTime, EndTime = info.EndTime, ShortDesc = info.ShortDesc, ShopId = info.ShopId, CreateTime = DateTime.Now }; var ret1 = DbFactory.Default.Add(model); var products = info.Products.Select(p => new CollocationPoruductInfo { ColloId = model.Id, ProductId = p.ProductId, DisplaySequence = p.DisplaySequence, IsMain = p.IsMain }).ToList(); var ret2 = DbFactory.Default.AddRange(products); var skus = info.Products.SelectMany(p => { var pro = products.FirstOrDefault(o => o.ProductId == p.ProductId); return(p.SKUs.Select(s => new CollocationSkuInfo { ColloProductId = pro.Id, Price = s.Price, ProductId = p.ProductId, SkuID = s.SKUId, SkuPirce = s.SKUPrice, })); }); var ret3 = DbFactory.Default.Add(skus); }); }
public ActionResult Edit(long id) { CollocationInfo collocation = ServiceHelper.Create <ICollocationService>().GetCollocation(id); if (collocation.ShopId != base.CurrentSellerManager.ShopId) { RedirectToAction("Management"); } CollocationDataModel collocationDataModel = new CollocationDataModel() { CreateTime = collocation.CreateTime.Value, EndTime = collocation.EndTime, ShopId = collocation.ShopId, ShortDesc = collocation.ShortDesc, Title = collocation.Title, StartTime = collocation.StartTime, Id = collocation.Id, CollocationPoruducts = collocation.ChemCloud_CollocationPoruducts.Select <CollocationPoruductInfo, CollocationPoruductModel>((CollocationPoruductInfo a) => { List <SKUInfo> list = a.ChemCloud_Products.SKUInfo.ToList(); return(new CollocationPoruductModel() { Id = a.Id, ColloId = a.ColloId, DisplaySequence = a.DisplaySequence.Value, IsMain = a.IsMain, ProductId = a.ProductId, ProductName = a.ChemCloud_Products.ProductName, ImagePath = a.ChemCloud_Products.ImagePath, CollocationSkus = a.ChemCloud_CollocationSkus.Select <CollocationSkuInfo, CollocationSkus>((CollocationSkuInfo b) => { SKUInfo sKUInfo = list.FirstOrDefault((SKUInfo t) => t.Id == b.SkuID); return new CollocationSkus() { Id = b.Id, Price = b.Price, SkuID = b.SkuID, SKUName = string.Concat(new string[] { sKUInfo.Color, " ", sKUInfo.Size, " ", sKUInfo.Version }), SkuPirce = b.SkuPirce.Value, ColloProductId = b.ColloProductId, ProductId = b.ProductId }; }).ToList() }); }).OrderBy <CollocationPoruductModel, int>((CollocationPoruductModel a) => a.DisplaySequence).ToList() }; dynamic viewBag = base.ViewBag; DateTime dateTime = ServiceHelper.Create <IMarketService>().GetMarketService(base.CurrentSellerManager.ShopId, MarketType.Collocation).MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo item) => item.EndTime); viewBag.EndTime = dateTime.ToString("yyyy-MM-dd"); return(View(collocationDataModel)); }
public void AddCollocation(CollocationInfo info) { CheckCollocationDate(info.ShopId, info.EndTime); var date = DateTime.Now.Date; var mainId = info.Himall_CollocationPoruducts.Where(a => a.IsMain = true).Select(a => a.ProductId).FirstOrDefault(); if (Context.CollocationPoruductInfo.Any(a => a.IsMain && a.ProductId == mainId && a.Himall_Collocation.EndTime > date)) { throw new HimallException("此主商品已存在组合购,请勿重复添加!"); } Context.CollocationInfo.Add(info); Context.SaveChanges(); }
public ActionResult AddCollocation(string collocationjson) { var model = Newtonsoft.Json.JsonConvert.DeserializeObject <CollocationDataModel>(collocationjson); if (model == null) { throw new HimallException("添加组合购参数错误!"); } if (model.Title.Trim().Length <= 0) { throw new HimallException("组合购的标题不能为空!"); } if (model.ShortDesc.Length >= 500) { throw new HimallException("组合描述不能超过500字!"); } Himall.Model.CollocationInfo m = new CollocationInfo(); m.CreateTime = DateTime.Now; m.EndTime = model.EndTime; m.ShopId = CurrentSellerManager.ShopId; m.ShortDesc = model.ShortDesc; m.Title = model.Title; m.StartTime = model.StartTime; m.Id = model.Id; m.Himall_CollocationPoruducts = model.CollocationPoruducts.Select(a => new Himall.Model.CollocationPoruductInfo { Id = a.Id, ColloId = a.ColloId, DisplaySequence = a.DisplaySequence, IsMain = a.IsMain, ProductId = a.ProductId, Himall_CollocationSkus = a.CollocationSkus.Select(b => new Himall.Model.CollocationSkuInfo() { Id = b.Id, Price = b.Price, SkuID = b.SkuID, SkuPirce = b.SkuPirce, ColloProductId = b.ColloProductId, ProductId = b.ProductId }).ToArray() }).ToArray(); _iCollocationService.AddCollocation(m); return(Json(new Result() { success = true, msg = "添加成功!" })); }
public ActionResult AddCollocation(string collocationjson) { CollocationDataModel collocationDataModel = JsonConvert.DeserializeObject <CollocationDataModel>(collocationjson); if (collocationDataModel == null) { throw new HimallException("添加组合购参数错误!"); } CollocationInfo collocationInfo = new CollocationInfo() { CreateTime = new DateTime?(DateTime.Now), EndTime = collocationDataModel.EndTime, ShopId = base.CurrentSellerManager.ShopId, ShortDesc = collocationDataModel.ShortDesc, Title = collocationDataModel.Title, StartTime = collocationDataModel.StartTime, Id = collocationDataModel.Id, Himall_CollocationPoruducts = ( from a in collocationDataModel.CollocationPoruducts select new CollocationPoruductInfo() { Id = a.Id, ColloId = a.ColloId, DisplaySequence = new int?(a.DisplaySequence), IsMain = a.IsMain, ProductId = a.ProductId, Himall_CollocationSkus = ( from b in a.CollocationSkus select new CollocationSkuInfo() { Id = b.Id, Price = b.Price, SkuID = b.SkuID, SkuPirce = new decimal?(b.SkuPirce), ColloProductId = b.ColloProductId, ProductId = b.ProductId }).ToArray() }).ToArray() }; ServiceHelper.Create <ICollocationService>().AddCollocation(collocationInfo); Result result = new Result() { success = true, msg = "添加成功!" }; return(Json(result)); }
public void EditCollocation(CollocationInfo info) { CollocationInfo title = context.CollocationInfo.FirstOrDefault((CollocationInfo a) => a.Id == info.Id); if (title.EndTime < DateTime.Now.Date) { throw new HimallException("该活动已结束,无法修改!"); } context.CollocationPoruductInfo.RemoveRange(title.Himall_CollocationPoruducts); title.Title = info.Title; title.ShortDesc = info.ShortDesc; title.StartTime = info.StartTime; title.EndTime = info.EndTime; title.ShopId = info.ShopId; title.Himall_CollocationPoruducts = info.Himall_CollocationPoruducts; context.SaveChanges(); }
public void AddCollocation(CollocationInfo info) { DateTime date = DateTime.Now.Date; long num1 = info.Himall_CollocationPoruducts.Where((CollocationPoruductInfo a) => { bool flag = true; a.IsMain = flag; return(flag); }).Select <CollocationPoruductInfo, long>((CollocationPoruductInfo a) => a.ProductId).FirstOrDefault(); if (context.CollocationPoruductInfo.Any((CollocationPoruductInfo a) => a.IsMain && a.ProductId == num1 && (a.Himall_Collocation.EndTime > date))) { throw new HimallException("此主商品已存在组合购,请勿重复添加!"); } context.CollocationInfo.Add(info); context.SaveChanges(); }
public void EditCollocation(CollocationInfo info) { CheckCollocationDate(info.ShopId, info.EndTime); var coll = Context.CollocationInfo.FirstOrDefault(a => a.Id == info.Id); if (coll.EndTime < DateTime.Now.Date) { throw new HimallException("该活动已结束,无法修改!"); } Context.CollocationPoruductInfo.RemoveRange(coll.Himall_CollocationPoruducts); coll.Title = info.Title; coll.ShortDesc = info.ShortDesc; coll.StartTime = info.StartTime; coll.EndTime = info.EndTime; coll.ShopId = info.ShopId; coll.Himall_CollocationPoruducts = info.Himall_CollocationPoruducts; Context.SaveChanges(); }
/// <summary> /// 诊所修改一个组合购 /// </summary> /// <param name="info"></param> public static void EditCollocation(CollocationInfo info) { _iCollocationService.EditCollocation(info); }
/// <summary> /// 诊所添加一个组合购 /// </summary> /// <param name="info"></param> public static void AddCollocation(CollocationInfo info) { _iCollocationService.AddCollocation(info); }