/// <summary> /// 删除信息信息 /// </summary> /// <param name="ids">要删除的信息编号</param> /// <returns>业务操作结果</returns> public OperationResult DeleteExpressTemplates(params int[] ids) { return(ExpressTemplateRepository.Delete(ids)); }
/// <summary> /// 添加信息信息 /// </summary> /// <param name="inputDtos">要添加的信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> AddExpressTemplates(params ExpressTemplateDto[] inputDtos) { ExpressTemplateRepository.UnitOfWork.TransactionEnabled = true; List <string> names = new List <string>(); foreach (ExpressTemplateDto dto in inputDtos) { //ExpressTemplate expressTemplate = dto.MapTo<ExpressTemplate>(); ExpressTemplate expressTemplate = new ExpressTemplate() { Name = dto.Name, DeliverAddress = dto.DeliverAddress, DeliverTime = dto.DeliverTime, IsFree = dto.IsFree, Count = dto.Count, Price = dto.Price, CountAdd = dto.CountAdd, PriceAdd = dto.PriceAdd }; //店铺 if (dto.ShopId.HasValue && dto.ShopId.Value > 0) { Shop.Models.Shop shop = await ShopRepository.GetByKeyAsync(dto.ShopId.Value); if (shop == null) { return(new OperationResult(OperationResultType.QueryNull, "店铺不存在")); } expressTemplate.Shop = shop; shop.ExpressTemplates.Add(expressTemplate); } //特殊地区 if (dto.SpecialExpressAddresses.Count > 0) { foreach (Hmh.Core.Shop.Dtos.SpecialExpressAddress specialExpressAddressDto in dto.SpecialExpressAddresses) { //Hmh.Core.Shop.Models.SpecialExpressAddress specialExpressAddress = specialExpressAddressDto.MapTo<Hmh.Core.Shop.Models.SpecialExpressAddress>(); Hmh.Core.Shop.Models.SpecialExpressAddress specialExpressAddress = new Hmh.Core.Shop.Models.SpecialExpressAddress() { Address = specialExpressAddressDto.Address, Count = specialExpressAddressDto.Count, Price = specialExpressAddressDto.Price, CountAdd = specialExpressAddressDto.CountAdd, PriceAdd = specialExpressAddressDto.PriceAdd }; await SpecialExpressAddressRepository.InsertAsync(specialExpressAddress); specialExpressAddress.ExpressTemplate = expressTemplate; expressTemplate.SpecialExpressAddresses.Add(specialExpressAddress); } } int id = await ExpressTemplateRepository.InsertAsync(expressTemplate); //if (!(id > 0)) // return new OperationResult(OperationResultType.Error, "添加失败"); names.Add(expressTemplate.Name); } return(await ExpressTemplateRepository.UnitOfWork.SaveChangesAsync() > 0 ? new OperationResult(OperationResultType.Success, $"模板“{names.ExpandAndToString()}”创建成功") : OperationResult.NoChanged); }
/// <summary> /// 添加店铺信息信息 /// </summary> /// <param name="inputDtos">要添加的店铺信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> AddGoodss(params GoodsInputDto[] inputDtos) { GoodsRepository.UnitOfWork.TransactionEnabled = true; List <string> names = new List <string>(); foreach (GoodsInputDto dto in inputDtos) { Models.Goods goods = new Models.Goods()//商品其他属性的绑定 { Name = dto.Name, GoodsPics = dto.GoodsPics, Description = dto.Description, Detail = dto.Detail, Price = dto.Price, Stock = dto.Stock, GoodsNumber = dto.GoodsNumber, BarCode = dto.BarCode, CreatedTime = DateTime.Now, BeginTime = DateTime.Now, IsGuarantee = dto.IsGuarantee, IsReceipt = dto.IsReceipt, IsSevenDayReplacement = dto.IsSevenDayReplacement, IsReplacement = dto.IsReplacement, IsCommend = dto.IsCommend, IsLocked = false }; //店铺 if (dto.ShopId.HasValue && dto.ShopId.Value > 0) { Shop.Models.Shop shop = await ShopRepository.GetByKeyAsync(dto.ShopId.Value); if (shop == null) { return(new OperationResult(OperationResultType.QueryNull, "店铺不存在")); } goods.Shop = shop; shop.Goodses.Add(goods); } //分类 if (dto.CategoryId.HasValue && dto.CategoryId.Value > 0) { Category category = await CategoryRepository.GetByKeyAsync(dto.CategoryId.Value); if (category == null) { return(new OperationResult(OperationResultType.QueryNull, "发布不存在")); } goods.Category = category; category.Goodses.Add(goods); } //运费模板 if (dto.ExpressTemplateId.HasValue && dto.ExpressTemplateId.Value > 0) { Shop.Models.ExpressTemplate expressTemplate = await ExpressTemplateRepository.GetByKeyAsync(dto.ExpressTemplateId.Value); if (expressTemplate == null) { return(new OperationResult(OperationResultType.QueryNull, "运费模板不存在")); } goods.ExpressTemplate = expressTemplate; } //商品属性 if (dto.GoodsAttrs.Count > 0) { foreach (Dtos.GoodsAttr goodsAttrDto in dto.GoodsAttrs) { //Hmh.Core.Shop.Models.SpecialExpressAddress specialExpressAddress = specialExpressAddressDto.MapTo<Hmh.Core.Shop.Models.SpecialExpressAddress>(); Models.GoodsAttr goodsAttr = new Models.GoodsAttr() { AttrName = goodsAttrDto.AttrName, AttrValue = goodsAttrDto.AttrValue }; await GoodsAttrRepository.InsertAsync(goodsAttr); goodsAttr.Goods = goods; goods.GoodsAttrs.Add(goodsAttr); } } //商品Sku if (dto.Skus.Count > 0) { foreach (Dtos.Sku skuDto in dto.Skus) { if (skuDto.Names.Count != skuDto.Values.Count) { return(new OperationResult(OperationResultType.Error, "规格名称和值不对应")); } Models.Sku sku = new Models.Sku() { Names = skuDto.Names.ExpandAndToString(), Values = skuDto.Values.ExpandAndToString(), Price = skuDto.Price, Stock = skuDto.Stock, GoodsNumber = skuDto.GoodsNumber, BarCode = skuDto.BarCode, SkuPic = skuDto.SkuPic }; await SkuRepository.InsertAsync(sku); sku.Goods = goods; goods.Skus.Add(sku); } } int id = await GoodsRepository.InsertAsync(goods); //if (!(id > 0)) // return new OperationResult(OperationResultType.Error, "添加失败"); names.Add(goods.Name); } return(await GoodsRepository.UnitOfWork.SaveChangesAsync() > 0 ? new OperationResult(OperationResultType.Success, $"商品“{names.ExpandAndToString()}”创建成功") : OperationResult.NoChanged); }