/// <summary> /// convert debitMemo to list model /// </summary> /// <param name="memo"></param> /// <returns></returns> public DebitMemoViewModel ConvertToListView(DebitMemo memo) { DebitMemoViewModel model = new DebitMemoViewModel(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _foundryInvoiceRepository = new FoundryInvoiceRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _creditMemoRepository = new CreditMemoRepository(); var foundryInvoice = _foundryInvoiceRepository.GetFoundryInvoice(memo.FoundryInvoiceId ?? Guid.Empty); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(memo.FoundryId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(memo.CustomerId); var creditMemo = _creditMemoRepository.GetCreditMemoByDebitMemo(memo.DebitMemoId); model.DebitMemoId = memo.DebitMemoId; model.CustomerId = memo.CustomerId; model.FoundryId = (dynamicsFoundry != null) ? dynamicsFoundry.VENDORID : "N/A"; model.DebitMemoNumber = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A"; model.InvoiceNumber = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A"; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.DebitMemoDate = memo.DebitMemoDate; model.DebitMemoDateStr = memo.DebitMemoDate.ToShortDateString(); model.DebitAmount = memo.Amount; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.CreditMemoId = (creditMemo != null) ? creditMemo.CreditMemoId : Guid.Empty; model.CreditMemoNumber = (creditMemo != null && !string.IsNullOrEmpty(creditMemo.Number)) ? creditMemo.Number : "N/A"; model.IsOpen = memo.IsOpen; model.IsClosed = memo.IsClosed; model.CreatedDate = (memo.CreatedDate != null) ? memo.CreatedDate : DateTime.MinValue; model.CreatedBy = memo.CreatedBy; if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_foundryInvoiceRepository != null) { _foundryInvoiceRepository.Dispose(); _foundryInvoiceRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_creditMemoRepository != null) { _creditMemoRepository.Dispose(); _creditMemoRepository = 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 debitMemo to view model /// </summary> /// <param name="memo"></param> /// <returns></returns> public DebitMemoViewModel ConvertToView(DebitMemo memo) { DebitMemoViewModel model = new DebitMemoViewModel(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _foundryInvoiceRepository = new FoundryInvoiceRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _salespersonDynamicsRepository = new SalespersonDynamicsRepository(); var _debitMemoRepository = new DebitMemoRepository(); var _creditMemoRepository = new CreditMemoRepository(); var foundryInvoice = _foundryInvoiceRepository.GetFoundryInvoice(memo.FoundryInvoiceId ?? Guid.Empty); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(memo.FoundryId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(memo.CustomerId); var dyanmicsSalesperson = _salespersonDynamicsRepository.GetSalesperson((dynamicsCustomer != null) ? dynamicsCustomer.SLPRSNID : string.Empty); var creditMemo = _creditMemoRepository.GetCreditMemoByDebitMemo(memo.DebitMemoId); var items = _debitMemoRepository.GetDebitMemoItems().Where(x => x.DebitMemoId == memo.DebitMemoId).ToList(); var attachments = _debitMemoRepository.GetDebitMemoAttachments().Where(x => x.DebitMemoId == memo.DebitMemoId).ToList(); model.DebitMemoId = memo.DebitMemoId; model.FoundryInvoiceId = memo.FoundryInvoiceId; model.InvoiceNumber = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A"; model.DebitMemoNumber = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A"; model.DebitMemoDate = memo.DebitMemoDate; model.DebitMemoDateStr = (memo.DebitMemoDate != null) ? memo.DebitMemoDate.ToShortDateString() : "N/A"; model.FoundryId = memo.FoundryId; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.CustomerId = memo.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.SalespersonId = memo.SalespersonId; model.SalespersonName = (dyanmicsSalesperson != null && !string.IsNullOrEmpty(dyanmicsSalesperson.SLPRSNFN)) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A"; model.CreditMemoId = (creditMemo != null) ? creditMemo.CreditMemoId : Guid.Empty; model.CreditMemoNumber = (creditMemo != null && !string.IsNullOrEmpty(creditMemo.Number)) ? creditMemo.Number : "N/A"; model.RmaNumber = (!string.IsNullOrEmpty(memo.RmaNumber)) ? memo.RmaNumber : "N/A"; model.TrackingNumber = (!string.IsNullOrEmpty(memo.TrackingNumber)) ? memo.TrackingNumber : "N/A"; model.DebitAmount = memo.Amount; model.DebitMemoNotes = (!string.IsNullOrEmpty(memo.Notes)) ? memo.Notes : "N/A"; model.IsOpen = memo.IsOpen; model.IsClosed = memo.IsClosed; model.Status = memo.IsOpen ? "Open" : memo.IsClosed ? "Closed" : "N/A"; if (items != null && items.Count > 0) { var debitMemoItems = new List <DebitMemoItemViewModel>(); foreach (var item in items) { DebitMemoItemViewModel debitMemoItem = new DebitMemoItemConverter().ConvertToView(item); debitMemoItems.Add(debitMemoItem); } model.DebitMemoItems = debitMemoItems; } if (attachments != null && attachments.Count > 0) { var debitMemoAttachments = new List <DebitMemoAttachmentViewModel>(); foreach (var attachment in attachments) { var attachmentModel = new DebitMemoAttachmentConverter().ConvertToView(attachment); debitMemoAttachments.Add(attachmentModel); } model.Attachments = debitMemoAttachments; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_foundryInvoiceRepository != null) { _foundryInvoiceRepository.Dispose(); _foundryInvoiceRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_salespersonDynamicsRepository != null) { _salespersonDynamicsRepository.Dispose(); _salespersonDynamicsRepository = null; } if (_creditMemoRepository != null) { _creditMemoRepository.Dispose(); _creditMemoRepository = null; } if (_debitMemoRepository != null) { _debitMemoRepository.Dispose(); _debitMemoRepository = null; } return(model); }