/// <summary> /// convert container to view model /// </summary> /// <param name="container"></param> /// <returns></returns> public ContainerViewModel ConvertToView(Container container) { ContainerViewModel model = new ContainerViewModel(); var _containerRepository = new ContainerRepository(); var containerParts = _containerRepository.GetContainerParts().Where(x => x.ContainerId == container.ContainerId).ToList(); model.ContainerId = container.ContainerId; model.BillOfLadingId = container.BillOfLadingId; model.ContainerNumber = (!string.IsNullOrEmpty(container.Number)) ? container.Number : "N/A"; if (containerParts != null && containerParts.Count > 0) { model.ContainerParts = new List <ContainerPartViewModel>(); foreach (var containerPart in containerParts) { ContainerPartViewModel convertedModel = new ContainerPartConverter().ConvertToView(containerPart); model.ContainerParts.Add(convertedModel); } } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } return(model); }
/// <summary> /// convert containerPart to view model /// </summary> /// <param name="containerPart"></param> /// <returns></returns> public ContainerPartViewModel ConvertToView(ContainerPart containerPart) { ContainerPartViewModel model = new ContainerPartViewModel(); var _containerRepository = new ContainerRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var container = _containerRepository.GetContainer(containerPart.ContainerId); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderParts().FirstOrDefault(x => x.FoundryOrderPartId == containerPart.FoundryOrderPartId); var part = _partRepository.GetPart((foundryOrderPart != null) ? foundryOrderPart.PartId : Guid.Empty); var dynamicsPart = _dynamicsPartRepository.GetPartMaster(part != null && !string.IsNullOrEmpty(part.Number) ? part.Number : null); var foundryOrder = _foundryOrderRepository.GetFoundryOrder((foundryOrderPart != null) ? foundryOrderPart.FoundryOrderId : Guid.Empty); model.FoundryOrderPartId = containerPart.FoundryOrderPartId; model.ContainerPartId = containerPart.ContainerPartId; model.ContainerId = containerPart.ContainerId; model.PartId = (part != null) ? part.PartId : Guid.Empty; model.ContainerNumber = (container != null) ? container.Number : "N/A"; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.FoundryOrderId = (foundryOrder != null) ? foundryOrder.FoundryOrderId : Guid.Empty; model.OrderNumber = (foundryOrder != null && !string.IsNullOrEmpty(foundryOrder.Number)) ? foundryOrder.Number : "N/A"; model.PalletNumber = (!string.IsNullOrEmpty(containerPart.PalletNumber)) ? containerPart.PalletNumber : "N/A"; model.Quantity = containerPart.Quantity; model.Weight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.Cost = foundryOrderPart.Cost; model.Price = foundryOrderPart.Price; model.AvailableQuantity = (foundryOrderPart != null) ? foundryOrderPart.Quantity : 0; model.ShipCode = (foundryOrderPart != null && !string.IsNullOrEmpty(foundryOrderPart.ShipCode)) ? foundryOrderPart.ShipCode : "N/A"; if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }
/// <summary> /// convert bol to view model /// </summary> /// <param name="bol"></param> /// <returns></returns> public BillOfLadingViewModel ConvertToView(BillOfLading bol) { BillOfLadingViewModel model = new BillOfLadingViewModel(); var _bolRepository = new BillOfLadingRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _foundryInvoiceRepository = new FoundryInvoiceRepository(); var _containerRepository = new ContainerRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(bol.FoundryId); var foundryInvoice = _foundryInvoiceRepository.GetFoundryInvoiceByBillOfLading(bol.BillOfLadingId); var containers = _containerRepository.GetContainers().Where(x => x.BillOfLadingId == bol.BillOfLadingId).ToList(); model.BillOfLadingId = bol.BillOfLadingId; model.ShipmentId = bol.ShipmentId; model.FoundryId = bol.FoundryId; model.BolNumber = (!string.IsNullOrEmpty(bol.Number)) ? bol.Number : "N/A"; model.BolDate = bol.BolDate; model.BolDateStr = (bol.BolDate != null) ? bol.BolDate.ToShortDateString() : "N/A"; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.Description = (!string.IsNullOrEmpty(bol.Description)) ? bol.Description : "N/A"; model.HasLcl = bol.HasLcl; model.HasDoorMove = bol.HasDoorMove; model.HasArrivalNotice = bol.HasArrivalNotice; model.HasOriginalDocuments = bol.HasOriginalDocuments; model.PalletCount = bol.PalletCount; model.GrossWeight = bol.GrossWeight; model.NetWeight = bol.NetWeight; model.BolNotes = (!string.IsNullOrEmpty(bol.Notes)) ? bol.Notes : "N/A"; model.WireInstructions = (!string.IsNullOrEmpty(bol.WireInstructions)) ? bol.WireInstructions : "N/A"; model.CustomsNumber = (!string.IsNullOrEmpty(bol.CustomsNumber)) ? bol.CustomsNumber : "N/A"; model.IsCustomsLiquidated = bol.IsCustomsLiquidated; model.FoundryInvoiceId = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty; model.BillOfLadingId = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty; model.InvoiceNumber = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A"; model.InvoiceTotal = (foundryInvoice != null) ? foundryInvoice.Amount : 0.00m; model.ScheduledDate = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate : DateTime.MinValue; model.ScheduledDateStr = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate.Value.ToShortDateString() : "N/A"; model.ActualDate = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate : DateTime.MinValue; model.ActualDateStr = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate.Value.ToShortDateString() : "N/A"; model.InvoiceNotes = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Notes)) ? foundryInvoice.Notes : "N/A"; model.HasBeenAnalyzed = bol.HasBeenAnalyzed; if (containers != null && containers.Count > 0) { model.Containers = new List <ContainerViewModel>(); foreach (var container in containers) { ContainerViewModel convertedModel = new ContainerConverter().ConvertToView(container); model.Containers.Add(convertedModel); } model.ContainerParts = new List <ContainerPartViewModel>(); model.Pallets = new List <PalletViewModel>(); model.PurchaseOrders = new List <FoundryOrderViewModel>(); foreach (var container in model.Containers) { if (container.ContainerParts != null) { foreach (var containerPart in container.ContainerParts) { model.ContainerParts.Add(containerPart); model.Pallets.Add(new PalletViewModel() { PalletNumber = containerPart.PalletNumber }); var foundryOrder = _foundryOrderRepository.GetFoundryOrder(containerPart.FoundryOrderId); if (foundryOrder != null) { FoundryOrderViewModel convertedModel = new FoundryOrderConverter().ConvertToView(foundryOrder); model.PurchaseOrders.Add(convertedModel); } } } } if (model.PurchaseOrders != null && model.PurchaseOrders.Count > 0) { model.PurchaseOrders = model.PurchaseOrders.GroupBy(x => x.FoundryOrderId).Select(y => y.First()).ToList(); } if (model.Pallets != null && model.Pallets.Count > 0) { model.Pallets = model.Pallets.Distinct().ToList(); } } model.FoundryInvoice = new FoundryInvoiceConverter().ConvertToView(foundryInvoice); if (_bolRepository != null) { _bolRepository.Dispose(); _bolRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_foundryInvoiceRepository != null) { _foundryInvoiceRepository.Dispose(); _foundryInvoiceRepository = null; } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }
/// <summary> /// convert container part to warehouse inventory list model /// </summary> /// <param name="containerPart"></param> /// <returns></returns> public WarehouseInventoryViewModel ConvertToListView(ContainerPart containerPart) { WarehouseInventoryViewModel model = new WarehouseInventoryViewModel(); var _foundryOrderRepository = new FoundryOrderRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _containerRepository = new ContainerRepository(); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderPart(containerPart.FoundryOrderPartId); var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart((foundryOrderPart != null) ? foundryOrderPart.CustomerOrderPartId : Guid.Empty); var part = _partRepository.GetPart((foundryOrderPart != null) ? foundryOrderPart.PartId : Guid.Empty); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : string.Empty); var container = _containerRepository.GetContainer(containerPart.ContainerId); model.CustomerId = (part != null) ? part.CustomerId : "N/A"; model.ShipCode = (foundryOrderPart != null) ? foundryOrderPart.ShipCode : "N/A"; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartWeight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.PalletNumber = (!string.IsNullOrEmpty(part.Number)) ? containerPart.PalletNumber : "N/A"; model.PalletQuantity = containerPart.Quantity; model.TotalQuantity = containerPart.Quantity; model.ContainerNumber = (!string.IsNullOrEmpty(part.Number)) ? container.Number : "N/A"; model.PONumber = (customerOrderPart != null && !string.IsNullOrEmpty(customerOrderPart.CustomerOrder.PONumber)) ? customerOrderPart.CustomerOrder.PONumber : "N/A"; model.WarehouseDate = (foundryOrderPart != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue; model.WarehouseDateStr = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A"; model.SixtyDaysDate = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.AddDays(60) : DateTime.MinValue; model.SixtyDaysDateStr = (model.SixtyDaysDate != null) ? model.SixtyDaysDate.Value.ToShortDateString() : "N/A"; if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } return(model); }