/// <summary> /// convert memo to list model /// </summary> /// <param name="memo"></param> /// <returns></returns> public CreditMemoViewModel ConvertToListView(CreditMemo memo) { CreditMemoViewModel model = new CreditMemoViewModel(); var _debitMemoRepository = new DebitMemoRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var debitMemo = _debitMemoRepository.GetDebitMemo(memo.DebitMemoId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(memo.CustomerId); model.CreditMemoId = memo.CreditMemoId; model.CreditMemoNumber = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A"; model.CustomerId = memo.CustomerId; model.FoundryId = (debitMemo != null) ? debitMemo.FoundryId : string.Empty; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.DebitMemoId = memo.DebitMemoId; model.DebitMemoNumber = (debitMemo != null && !string.IsNullOrEmpty(debitMemo.Number)) ? debitMemo.Number : "N/A"; model.CreditMemoDate = memo.CreditMemoDate; model.CreditMemoDateStr = memo.CreditMemoDate.ToShortDateString(); model.CreditAmount = memo.Amount; model.RmaNumber = (debitMemo != null && !string.IsNullOrEmpty(debitMemo.RmaNumber)) ? debitMemo.RmaNumber : "N/A"; if (_debitMemoRepository != null) { _debitMemoRepository.Dispose(); _debitMemoRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } return(model); }
/// <summary> /// convert memo to view model /// </summary> /// <param name="memo"></param> /// <returns></returns> public CreditMemoViewModel ConvertToView(CreditMemo memo) { CreditMemoViewModel model = new CreditMemoViewModel(); var _debitMemoRepository = new DebitMemoRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _salespersonDynamicsRepository = new SalespersonDynamicsRepository(); var _creditMemoRepository = new CreditMemoRepository(); var debitMemo = _debitMemoRepository.GetDebitMemo(memo.DebitMemoId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(memo.CustomerId); var dyanmicsSalesperson = _salespersonDynamicsRepository.GetSalesperson(!string.IsNullOrEmpty(memo.SalespersonId) ? memo.SalespersonId : "N/A"); var items = _creditMemoRepository.GetCreditMemoItems().Where(x => x.CreditMemoId == memo.CreditMemoId).ToList(); model.CreditMemoId = memo.CreditMemoId; model.DebitMemoId = memo.DebitMemoId; model.DebitMemoNumber = (debitMemo != null && !string.IsNullOrEmpty(debitMemo.Number)) ? debitMemo.Number : "N/A"; model.CreditMemoNumber = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A"; model.CreditMemoDate = memo.CreditMemoDate; model.CreditMemoDateStr = memo.CreditMemoDate.ToShortDateString(); 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(memo.SalespersonId)) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A"; model.CreditAmount = memo.Amount; model.CreditMemoNotes = (!string.IsNullOrEmpty(memo.Number)) ? memo.Notes : "N/A"; if (items != null && items.Count > 0) { var creditMemoItems = new List <CreditMemoItemViewModel>(); foreach (var item in items) { CreditMemoItemViewModel creditMemoItem = new CreditMemoItemConverter().ConvertToView(item); creditMemoItems.Add(creditMemoItem); } model.CreditMemoItems = creditMemoItems; } if (_debitMemoRepository != null) { _debitMemoRepository.Dispose(); _debitMemoRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_salespersonDynamicsRepository != null) { _salespersonDynamicsRepository.Dispose(); _salespersonDynamicsRepository = null; } if (_creditMemoRepository != null) { _creditMemoRepository.Dispose(); _creditMemoRepository = 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); }