private async Task CreateSellAsync(CreateOrUpdateOutOrderInput input) { List <SellOrderDeListDto> list = input.OrderDetails;//表中要出库的物料信息,多个物料 double sum = 0; for (int i = 0; i < list.Count(); i++) { var detail = list[i]; if (detail.Count == 0 || "".Equals(detail.Count))//表中数量 { throw new UserFriendlyException($"物料[{detail.MaterielName}]销售数量不能为0!"); //temp = true; } else//表中有数量 { var storeStorage = await _storeManagerRepository.GetAll().Where(x => x.MaterielId == detail.MaterielId).ProjectTo <StoreManagerListDto>().ToListAsync(); if (storeStorage.Count == 0)//当前物料库存 { throw new UserFriendlyException($"物料[{detail.MaterielName}]库存为0,请采购!"); } else { //出库 var amount = 0; for (int k = 0; k < storeStorage.Count; k++) //20 { amount = amount + (int)storeStorage[k].CurrentAmount; //当前库存 } if (amount < detail.Count) { throw new UserFriendlyException($"[{detail.MaterielName}]库存量为[{amount}],低于销售量!"); } else { sum = sum + detail.OutPrice; } } } } var order = input.OutSell.MapTo <Sell>(); order.Code = "XS-" + DateTime.Now.ToString("yyyyMMdd-hhmmss"); order.Price = sum; order.IsOutbound = false; order.CustomerId = input.OutSell.CustomerId; var Code = order.Code; await _sellRepository.InsertAsync(order); //保存订单详情 for (int i = 0; i < list.Count(); i++) { var detail = list[i]; detail.OrderCode = Code; var dd = detail.MapTo <SellOrderDe>(); //保存订单详情 await _sellOrderDeRepository.InsertAsync(dd); } }
public async Task CreateOrUpdateOrder(CreateOrUpdateOutOrderInput input) { if (input.OutSell.Id.HasValue) { await UpdateSellAsync(input); } else { await CreateSellAsync(input); } }
private async Task UpdateSellAsync(CreateOrUpdateOutOrderInput input) { List <SellOrderDeListDto> list = input.OrderDetails;//表中要出库的物料信息,多个物料 var order = await _sellRepository.SingleAsync(x => x.Id == input.OutSell.Id.Value); double sum = 0; for (int i = 0; i < list.Count(); i++) { var etail = list[i]; sum = sum + etail.OutPrice; } order.CreationTime = input.OutSell.CreationTime; order.CustomerId = input.OutSell.CustomerId; order.Price = sum; await _sellRepository.UpdateAsync(order); //先删除订单的详细表,在修改订单详细表 var orderDetails = _sellOrderDeRepository.GetAll().Where(x => x.OrderCode.Equals(order.Code)).ToList(); for (int i = 0; i < orderDetails.Count(); i++) { var orderDetail = orderDetails[i]; await _sellOrderDeRepository.DeleteAsync(orderDetail); } for (int i = 0; i < list.Count(); i++) { var detail = list[i]; detail.OrderCode = input.OutSell.Code; var dd = detail.MapTo <SellOrderDe>(); await _sellOrderDeRepository.InsertAsync(dd); } }