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);
        }