public async Task <int> Create(GarmentShippingExportSalesDOViewModel viewModel) { GarmentShippingExportSalesDOModel garmentShippingExportSalesDOModel = MapToModel(viewModel); int Created = await _repository.InsertAsync(garmentShippingExportSalesDOModel); return(Created); }
public Task <int> InsertAsync(GarmentShippingExportSalesDOModel model) { model.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var item in model.Items) { item.FlagForCreate(_identityProvider.Username, UserAgent); } _dbSet.Add(model); return(_dbContext.SaveChangesAsync()); }
public void Read_Success() { var model = new GarmentShippingExportSalesDOModel("", "", 1, DateTimeOffset.Now, 1, "", "", "", "", 1, "", "", "", "", new List <GarmentShippingExportSalesDOItemModel>()); var repoMock = new Mock <IGarmentShippingExportSalesDORepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingExportSalesDOModel>() { 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 <GarmentShippingExportSalesDOItemModel>() { new GarmentShippingExportSalesDOItemModel(1, "", "", "", 1, 1, "", 1, 1, 1, 1) }; var model = new GarmentShippingExportSalesDOModel("", "", 1, DateTimeOffset.Now, 1, "", "", "", "", 1, "", "", "", "", items); var repoMock = new Mock <IGarmentShippingExportSalesDORepository>(); 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 GarmentShippingExportSalesDOModel MapToModel(GarmentShippingExportSalesDOViewModel viewModel) { var items = (viewModel.items ?? new List <GarmentShippingExportSalesDOItemViewModel>()).Select(i => { i.uom = i.uom ?? new UnitOfMeasurement(); i.comodity = i.comodity ?? new Comodity(); return(new GarmentShippingExportSalesDOItemModel(i.comodity.Id, i.comodity.Code, i.comodity.Name, i.description, i.quantity, i.uom.Id.GetValueOrDefault(), i.uom.Unit, i.cartonQuantity, i.grossWeight, i.nettWeight, i.volume) { Id = i.Id }); }).ToList(); viewModel.unit = viewModel.unit ?? new Unit(); viewModel.buyerAgent = viewModel.buyerAgent ?? new Buyer(); viewModel.exportSalesDONo = GenerateNo(viewModel); GarmentShippingExportSalesDOModel garmentPackingListModel = new GarmentShippingExportSalesDOModel(viewModel.exportSalesDONo, viewModel.invoiceNo, viewModel.packingListId, viewModel.date, viewModel.buyerAgent.Id, viewModel.buyerAgent.Code, viewModel.buyerAgent.Name, viewModel.to, viewModel.unit.Name, viewModel.unit.Id, viewModel.unit.Code, viewModel.shipmentMode, viewModel.deliverTo, viewModel.remark, items); return(garmentPackingListModel); }
public Task <int> UpdateAsync(int id, GarmentShippingExportSalesDOModel 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.SetUnitCode(model.UnitCode, _identityProvider.Username, UserAgent); modelToUpdate.SetUnitId(model.UnitId, _identityProvider.Username, UserAgent); modelToUpdate.SetUnitName(model.UnitName, _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.SetCartonQuantity(item.CartonQuantity, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityId(item.ComodityId, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityCode(item.ComodityCode, _identityProvider.Username, UserAgent); itemToUpdate.SetComodityName(item.ComodityName, _identityProvider.Username, UserAgent); itemToUpdate.SetQuantity(item.Quantity, _identityProvider.Username, UserAgent); itemToUpdate.SetUomId(item.UomId, _identityProvider.Username, UserAgent); itemToUpdate.SetUomUnit(item.UomUnit, _identityProvider.Username, UserAgent); itemToUpdate.SetDescription(item.Description, _identityProvider.Username, UserAgent); itemToUpdate.SetVolume(item.Volume, _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()); }
private GarmentShippingExportSalesDOViewModel MapToViewModel(GarmentShippingExportSalesDOModel model) { var vm = new GarmentShippingExportSalesDOViewModel() { 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, invoiceNo = model.InvoiceNo, buyerAgent = new Buyer { Id = model.BuyerAgentId, Code = model.BuyerAgentCode, Name = model.BuyerAgentName, }, date = model.Date, exportSalesDONo = model.ExportSalesDONo, packingListId = model.PackingListId, to = model.To, shipmentMode = model.ShipmentMode, deliverTo = model.DeliverTo, remark = model.Remark, unit = new Unit { Id = model.UnitId, Code = model.UnitCode, Name = model.UnitName, }, items = model.Items.Select(i => new GarmentShippingExportSalesDOItemViewModel { 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, comodity = new Comodity { Id = i.ComodityId, Code = i.ComodityCode, Name = i.ComodityName }, description = i.Description, quantity = i.Quantity, uom = new UnitOfMeasurement { Id = i.UomId, Unit = i.UomUnit }, cartonQuantity = i.CartonQuantity, exportSalesDOId = i.ExportSalesDOId, grossWeight = i.GrossWeight, nettWeight = i.NettWeight, volume = i.Volume }).ToList() }; return(vm); }
public async Task <int> Update(int id, GarmentShippingExportSalesDOViewModel viewModel) { GarmentShippingExportSalesDOModel garmentShippingExportSalesDOModel = MapToModel(viewModel); return(await _repository.UpdateAsync(id, garmentShippingExportSalesDOModel)); }