public async Task <AjaxResult> Add([FromBody] TransferOrderInputDto dto) { return(await AjaxResult.Business(async result => { Check.NotNull(dto, nameof(dto)); dto.Id = Guid.NewGuid(); if (!ModelState.IsValid) { result.Error("提交信息验证失败"); return; } if (dto.Items == null || dto.Items.Length <= 0) { result.Error("调拨单至少需要一个采购项"); return; } if (String.IsNullOrWhiteSpace(dto.Operator)) { dto.Operator = User.Identity.Name; } dto.DateTime = DateTime.Now; foreach (var item in dto.Items) { item.Id = Guid.NewGuid(); item.TransferOrderId = dto.Id; } await _transferOrderContract.AddTransferOrderAsync(dto, ServiceProvider); result.Type = AjaxResultType.Success; })); }
public async Task <AjaxResult> Update([FromBody] TransferOrderInputDto dto) { return(await AjaxResult.Business(async result => { Check.NotNull(dto, nameof(dto)); if (!ModelState.IsValid) { result.Error("提交信息验证失败"); return; } if (String.IsNullOrWhiteSpace(dto.Operator)) { dto.Operator = User.Identity.Name; } dto.DateTime = DateTime.Now; foreach (var item in dto.Items) { item.TransferOrderId = dto.Id; } await _transferOrderContract.UpdateTransferOrderAsync(dto); result.Type = AjaxResultType.Success; if (dto == null) { result.Error("找不到指定的调拨单信息"); } else { result.Success(dto); } })); }
public async Task <bool> UpdateTransferOrderAsync(TransferOrderInputDto dto) { var transferOrder = dto.MapTo <TransferOrder>(); await _transferOrderRepo.UpdateAsync(transferOrder); var items = dto.Items.Select(d => d.MapTo <TransferOrderItem>()).ToArray(); await _transferOrderItemRepo.UpdateAsync(items); return(true); }
public async Task <bool> AddTransferOrderAsync(TransferOrderInputDto dto, IServiceProvider serviceProvider) { if (dto.Items == null || dto.Items.Length <= 0) { return(false); } var transferOrder = dto.MapTo <TransferOrder>(); var items = dto.Items.Select(d => d.MapTo <TransferOrderItem>()).ToArray(); var inventoryRepo = serviceProvider.GetService <IRepository <Inventory, Guid> >(); var warehouseRepo = serviceProvider.GetService <IRepository <Kira.LaconicInvoicing.Warehouse.Entities.Warehouse, Guid> >(); var sourceWarehouse = await warehouseRepo.GetFirstAsync(w => w.Number == dto.SourceWarehouseNumber); var destWarehouse = await warehouseRepo.GetFirstAsync(w => w.Number == dto.DestWarehouseNumber); var sourceInventories = inventoryRepo.Query().Where(iv => iv.WarehouseId == sourceWarehouse.Id); var destInventories = inventoryRepo.Query().Where(iv => iv.WarehouseId == destWarehouse.Id); var updateInventories = new List <Inventory>(); var addInventories = new List <Inventory>(); var dt = DateTime.Now; foreach (var item in items) { if (sourceInventories.Any(iv => iv.Number == item.Number)) { var inventory = await sourceInventories.FirstOrDefaultAsync(iv => iv.Number == item.Number); inventory.Amount -= item.Amount; inventory.DateTime = dt; updateInventories.Add(inventory); } else if (destInventories.Any(iv => iv.Number == item.Number)) { var inventory = await destInventories.FirstOrDefaultAsync(iv => iv.Number == item.Number); inventory.Amount += item.Amount; inventory.DateTime = dt; updateInventories.Add(inventory); } else { var inventory = new Inventory() { Id = Guid.NewGuid(), WarehouseId = destWarehouse.Id, GoodsCategory = item.GoodsCategory, Number = item.Number, Amount = item.Amount, DateTime = dt }; addInventories.Add(inventory); } } await _transferOrderRepo.InsertAsync(transferOrder); await _transferOrderItemRepo.InsertAsync(items); if (updateInventories.Count > 0) { await inventoryRepo.UpdateAsync(updateInventories.ToArray()); } if (addInventories.Count > 0) { await inventoryRepo.InsertAsync(addInventories.ToArray()); } return(true); }