public Task <int> UpdateAsync(int id, GarmentShippingLocalSalesDOModel model) { var modelToUpdate = _dbSet .Include(i => i.Items) .FirstOrDefault(s => s.Id == id); modelToUpdate.SetDate(model.Date, _identityProvider.Username, UserAgent); modelToUpdate.SetTo(model.To, _identityProvider.Username, UserAgent); modelToUpdate.SetStorageDivision(model.StorageDivision, _identityProvider.Username, UserAgent); modelToUpdate.SetRemark(model.Remark, _identityProvider.Username, UserAgent); foreach (var itemToUpdate in modelToUpdate.Items) { var item = model.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id); if (item != null) { itemToUpdate.SetGrossWeight(item.GrossWeight, _identityProvider.Username, UserAgent); itemToUpdate.SetNettWeight(item.NettWeight, _identityProvider.Username, UserAgent); itemToUpdate.SetDescription(item.Description, _identityProvider.Username, UserAgent); } else { itemToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var item in model.Items.Where(w => w.Id == 0)) { modelToUpdate.Items.Add(item); } return(_dbContext.SaveChangesAsync()); }
public async Task <int> Create(GarmentShippingLocalSalesDOViewModel viewModel) { GarmentShippingLocalSalesDOModel garmentShippingLocalSalesDOModel = MapToModel(viewModel); int Created = await _repository.InsertAsync(garmentShippingLocalSalesDOModel); return(Created); }
public Task <int> InsertAsync(GarmentShippingLocalSalesDOModel model) { model.FlagForCreate(_identityProvider.Username, UserAgent); var salesNote = _salesNoteDbSet.FirstOrDefault(a => a.Id == model.LocalSalesNoteId); salesNote.SetIsUsed(true, _identityProvider.Username, UserAgent); foreach (var item in model.Items) { item.FlagForCreate(_identityProvider.Username, UserAgent); } _dbSet.Add(model); return(_dbContext.SaveChangesAsync()); }
private GarmentShippingLocalSalesDOModel MapToModel(GarmentShippingLocalSalesDOViewModel viewModel) { var items = (viewModel.items ?? new List <GarmentShippingLocalSalesDOItemViewModel>()).Select(i => { i.uom = i.uom ?? new UnitOfMeasurement(); i.product = i.product ?? new ProductViewModel(); return(new GarmentShippingLocalSalesDOItemModel(i.localSalesDOId, i.localSalesNoteItemId, i.product.id, i.product.code, i.product.name, i.description, i.quantity, i.uom.Id.GetValueOrDefault(), i.uom.Unit, i.packQuantity, i.packUom.Id.GetValueOrDefault(), i.packUom.Unit, i.grossWeight, i.nettWeight) { Id = i.Id }); }).ToList(); viewModel.buyer = viewModel.buyer ?? new Buyer(); viewModel.localSalesDONo = GenerateNo(viewModel); GarmentShippingLocalSalesDOModel garmentPackingListModel = new GarmentShippingLocalSalesDOModel(viewModel.localSalesDONo, viewModel.localSalesNoteNo, viewModel.localSalesNoteId, viewModel.date, viewModel.buyer.Id, viewModel.buyer.Code, viewModel.buyer.Name, viewModel.to, viewModel.storageDivision, viewModel.remark, items); return(garmentPackingListModel); }
public void Read_Success() { var model = new GarmentShippingLocalSalesDOModel("", "", 1, DateTimeOffset.Now, 1, "", "", "", "", "", new List <GarmentShippingLocalSalesDOItemModel>()); var repoMock = new Mock <IGarmentShippingLocalSalesDORepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingLocalSalesDOModel>() { model }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock.Object).Object); var result = service.Read(1, 25, "{}", "{}", null); Assert.NotEmpty(result.Data); }
public async Task ReadById_Success() { var items = new List <GarmentShippingLocalSalesDOItemModel>() { new GarmentShippingLocalSalesDOItemModel(1, 1, 1, "", "", "", 1, 1, "", 1, 1, "", 1, 1) }; var model = new GarmentShippingLocalSalesDOModel("", "", 1, DateTimeOffset.Now, 1, "", "", "", "", "", items); var repoMock = new Mock <IGarmentShippingLocalSalesDORepository>(); repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>())) .ReturnsAsync(model); var service = GetService(GetServiceProvider(repoMock.Object).Object); var result = await service.ReadById(1); Assert.NotNull(result); }
private GarmentShippingLocalSalesDOViewModel MapToViewModel(GarmentShippingLocalSalesDOModel model) { var vm = new GarmentShippingLocalSalesDOViewModel() { Active = model.Active, Id = model.Id, CreatedAgent = model.CreatedAgent, CreatedBy = model.CreatedBy, CreatedUtc = model.CreatedUtc, DeletedAgent = model.DeletedAgent, DeletedBy = model.DeletedBy, DeletedUtc = model.DeletedUtc, IsDeleted = model.IsDeleted, LastModifiedAgent = model.LastModifiedAgent, LastModifiedBy = model.LastModifiedBy, LastModifiedUtc = model.LastModifiedUtc, localSalesDONo = model.LocalSalesDONo, buyer = new Buyer { Id = model.BuyerId, Code = model.BuyerCode, Name = model.BuyerName, }, date = model.Date, localSalesNoteNo = model.LocalSalesNoteNo, localSalesNoteId = model.LocalSalesNoteId, to = model.To, storageDivision = model.StorageDivision, remark = model.Remark, items = model.Items == null ? new List <GarmentShippingLocalSalesDOItemViewModel>() : model.Items.Select(i => new GarmentShippingLocalSalesDOItemViewModel { Active = i.Active, Id = i.Id, CreatedAgent = i.CreatedAgent, CreatedBy = i.CreatedBy, CreatedUtc = i.CreatedUtc, DeletedAgent = i.DeletedAgent, DeletedBy = i.DeletedBy, DeletedUtc = i.DeletedUtc, IsDeleted = i.IsDeleted, LastModifiedAgent = i.LastModifiedAgent, LastModifiedBy = i.LastModifiedBy, LastModifiedUtc = i.LastModifiedUtc, product = new ProductViewModel { id = i.ProductId, code = i.ProductCode, name = i.ProductName }, description = i.Description, quantity = i.Quantity, uom = new UnitOfMeasurement { Id = i.UomId, Unit = i.UomUnit }, packQuantity = i.PackQuantity, packUom = new UnitOfMeasurement { Id = i.PackUomId, Unit = i.PackUomUnit }, localSalesDOId = i.LocalSalesDOId, grossWeight = i.GrossWeight, nettWeight = i.NettWeight, localSalesNoteItemId = i.LocalSalesNoteItemId }).ToList() }; return(vm); }
public async Task <int> Update(int id, GarmentShippingLocalSalesDOViewModel viewModel) { GarmentShippingLocalSalesDOModel garmentShippingLocalSalesDOModel = MapToModel(viewModel); return(await _repository.UpdateAsync(id, garmentShippingLocalSalesDOModel)); }