protected GarmentDraftPackingListItemModel MapToModel(GarmentDraftPackingListItemViewModel viewModel) { var details = (viewModel.Details ?? new List <GarmentDraftPackingListDetailViewModel>()).Select(d => { var sizes = (d.Sizes ?? new List <GarmentDraftPackingListDetailSizeViewModel>()).Select(s => { s.Size = s.Size ?? new SizeViewModel(); return(new GarmentDraftPackingListDetailSizeModel(s.Size.Id, s.Size.Size, s.Quantity) { Id = s.Id }); }).ToList(); return(new GarmentDraftPackingListDetailModel(d.Carton1, d.Carton2, d.Style, d.Colour, d.CartonQuantity, d.QuantityPCS, d.TotalQuantity, d.Length, d.Width, d.Height, d.GrossWeight, d.NetWeight, d.NetNetWeight, sizes, d.Index) { Id = d.Id }); }).ToList(); viewModel.BuyerBrand = viewModel.BuyerBrand ?? new Buyer(); viewModel.Uom = viewModel.Uom ?? new UnitOfMeasurement(); viewModel.Unit = viewModel.Unit ?? new Unit(); viewModel.Comodity = viewModel.Comodity ?? new Comodity(); viewModel.Buyer = viewModel.Buyer ?? new Buyer(); viewModel.Section = viewModel.Section ?? new Section(); GarmentDraftPackingListItemModel GarmentDraftPackingListItemModel = new GarmentDraftPackingListItemModel(viewModel.RONo, viewModel.SCNo, viewModel.BuyerBrand.Id, viewModel.BuyerBrand.Name, viewModel.Comodity.Id, viewModel.Comodity.Code, viewModel.Comodity.Name, viewModel.ComodityDescription, viewModel.Quantity, viewModel.Uom.Id.GetValueOrDefault(), viewModel.Uom.Unit, viewModel.PriceRO, viewModel.Price, viewModel.PriceFOB, viewModel.PriceCMT, viewModel.Amount, viewModel.Valas, viewModel.Unit.Id, viewModel.Unit.Code, viewModel.Article, viewModel.OrderNo, viewModel.Description, viewModel.DescriptionMd, viewModel.Buyer.Id, viewModel.Buyer.Code, viewModel.Section.Code, details, viewModel.Remarks); return(GarmentDraftPackingListItemModel); }
public async Task <int> Update(int id, GarmentDraftPackingListItemViewModel viewModel) { GarmentDraftPackingListItemModel draftItemModel = MapToModel(viewModel); foreach (var detail in draftItemModel.Details) { detail.SetNetNetWeight(detail.NetNetWeight == 0 ? 0.9 * detail.NetWeight : detail.NetNetWeight, _identityProvider.Username, UserAgent); } return(await _draftPackingListItemRepository.UpdateAsync(id, draftItemModel)); }
protected GarmentDraftPackingListItemViewModel MapToViewModel(GarmentDraftPackingListItemModel model) { var vm = new GarmentDraftPackingListItemViewModel() { 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, RONo = model.RONo, SCNo = model.SCNo, BuyerBrand = new Buyer { Id = model.BuyerBrandId, Name = model.BuyerBrandName }, Comodity = new Comodity { Id = model.ComodityId, Code = model.ComodityCode, Name = model.ComodityName }, ComodityDescription = model.ComodityDescription, Quantity = model.Quantity, Uom = new UnitOfMeasurement { Id = model.UomId, Unit = model.UomUnit }, PriceRO = model.PriceRO, Price = model.Price, PriceFOB = model.PriceFOB, PriceCMT = model.PriceCMT, Amount = model.Amount, Valas = model.Valas, Unit = new Unit { Id = model.UnitId, Code = model.UnitCode }, Article = model.Article, OrderNo = model.OrderNo, Description = model.Description, DescriptionMd = model.DescriptionMd, Section = new Section { Code = model.SectionCode }, Buyer = new Buyer { Id = model.BuyerId, Code = model.BuyerCode }, Remarks = model.Remarks, Details = (model.Details ?? new List <GarmentDraftPackingListDetailModel>()).Select(d => new GarmentDraftPackingListDetailViewModel { Active = d.Active, Id = d.Id, CreatedAgent = d.CreatedAgent, CreatedBy = d.CreatedBy, CreatedUtc = d.CreatedUtc, DeletedAgent = d.DeletedAgent, DeletedBy = d.DeletedBy, DeletedUtc = d.DeletedUtc, IsDeleted = d.IsDeleted, LastModifiedAgent = d.LastModifiedAgent, LastModifiedBy = d.LastModifiedBy, LastModifiedUtc = d.LastModifiedUtc, PackingListItemId = d.PackingListItemId, Carton1 = d.Carton1, Carton2 = d.Carton2, Style = d.Style, Colour = d.Colour, CartonQuantity = d.CartonQuantity, QuantityPCS = d.QuantityPCS, TotalQuantity = d.TotalQuantity, Length = d.Length, Width = d.Width, Height = d.Height, GrossWeight = d.GrossWeight, NetWeight = d.NetWeight, NetNetWeight = d.NetNetWeight, Index = d.Index, Sizes = (d.Sizes ?? new List <GarmentDraftPackingListDetailSizeModel>()).Select(s => new GarmentDraftPackingListDetailSizeViewModel { Active = s.Active, Id = s.Id, CreatedAgent = s.CreatedAgent, CreatedBy = s.CreatedBy, CreatedUtc = s.CreatedUtc, DeletedAgent = s.DeletedAgent, DeletedBy = s.DeletedBy, DeletedUtc = s.DeletedUtc, IsDeleted = s.IsDeleted, LastModifiedAgent = s.LastModifiedAgent, LastModifiedBy = s.LastModifiedBy, LastModifiedUtc = s.LastModifiedUtc, Size = new SizeViewModel { Id = s.SizeId, Size = s.Size }, Quantity = s.Quantity }).ToList() }).ToList(), }; return(vm); }