public void SaveBatchSupply(BatchSupplyDTO batchSupplyDTO) { var batchSupply = new BatchSupply() { BatchId = batchSupplyDTO.BatchId, SupplyId = Convert.ToInt64(batchSupplyDTO.SupplyId), Quantity = Convert.ToDouble(batchSupplyDTO.Quantity), CreatedOn = DateTime.Now }; this.UnitOfWork.Get <BatchSupply>().AddNew(batchSupply); this.UnitOfWork.SaveChanges(); }
public long SaveBatch(Batch batch, string userId) { var batchDTO = new DTO.BatchDTO() { BatchId = batch.BatchId, Name = batch.Name, SectorId = batch.SectorId, Quantity = batch.Quantity, BranchId = batch.BranchId, Deleted = batch.Deleted, CreatedBy = batch.CreatedBy, CreatedOn = batch.CreatedOn }; var batchId = this._dataService.SaveBatch(batchDTO, userId); if (batch.Supplies.Any()) { EF.Models.Supply supplyObject = new EF.Models.Supply(); foreach (var batchSupply in batch.Supplies) { var batchSupplyDTO = new BatchSupplyDTO() { BatchId = batchId, SupplyId = batchSupply.SupplyId, Quantity = batchSupply.Quantity, }; this._dataService.PurgeBatchSupply(batchId, batchSupply.SupplyId); this._dataService.SaveBatchSupply(batchSupplyDTO); var storeMaizeStock = new StoreMaizeStock() { SupplyId = batchSupply.SupplyId, Quantity = batchSupply.Quantity, StoreId = batch.StoreId, BranchId = batch.BranchId, SectorId = batch.SectorId, }; _supplyService.SaveStoreMaizeStock(storeMaizeStock, false); supplyObject = this._supplyDataService.GetSupply(batchSupply.SupplyId); var supply = new SupplyDTO() { Quantity = supplyObject.Quantity, SupplyDate = supplyObject.SupplyDate, //SupplyNumber = supplyObject.SupplyNumber, BranchId = supplyObject.BranchId, SupplierId = supplyObject.SupplierId, Amount = supplyObject.Amount, StoreId = supplyObject.StoreId, TruckNumber = supplyObject.TruckNumber, Price = supplyObject.Price, WeightNoteNumber = supplyObject.WeightNoteNumber, BagsOfStones = supplyObject.BagsOfStones, NormalBags = supplyObject.NormalBags, MoistureContent = supplyObject.MoistureContent, Deleted = supplyObject.Deleted, AmountToPay = supplyObject.AmountToPay, DeletedBy = supplyObject.DeletedBy, DeletedOn = supplyObject.DeletedOn, StatusId = Convert.ToInt64(supplyStatusIdInProgress), Used = true, SupplyId = supplyObject.SupplyId }; this._supplyDataService.SaveSupply(supply, userId); } } return(batchId); }