/// <summary> /// convert customer to list model /// </summary> /// <param name="customer"></param> /// <returns></returns> public CustomerViewModel ConvertToListView(RM00101_Customer customer) { CustomerViewModel model = new CustomerViewModel(); var _salespersonDynamicsRepository = new SalespersonDynamicsRepository(); var dyanmicsSalesperson = _salespersonDynamicsRepository.GetSalesperson(customer.SLPRSNID); model.CustomerId = customer.CUSTNMBR; model.CustomerNumber = customer.CUSTNMBR; model.ShortName = (!string.IsNullOrEmpty(customer.SHRTNAME.Replace(" ", string.Empty))) ? customer.SHRTNAME : "N/A"; model.ContactName = (!string.IsNullOrEmpty(customer.CNTCPRSN.Replace(" ", string.Empty))) ? customer.CNTCPRSN : "N/A"; model.SalespersonName = (dyanmicsSalesperson != null) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A"; model.IsActive = customer.INACTIVE != 1 ? true : false; if (_salespersonDynamicsRepository != null) { _salespersonDynamicsRepository.Dispose(); _salespersonDynamicsRepository = 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); }
/// <summary> /// convert customer to view model /// </summary> /// <param name="customer"></param> /// <returns></returns> public CustomerViewModel ConvertToView(RM00101_Customer customer) { CustomerViewModel model = new CustomerViewModel(); var _salespersonDynamicsRepository = new SalespersonDynamicsRepository(); var _paymentTermRepository = new PaymentTermRepository(); var _shipmentTermRepository = new ShipmentTermRepository(); var _stateRepository = new StateRepository(); var _countryRepository = new CountryRepository(); var dyanmicsSalesperson = _salespersonDynamicsRepository.GetSalesperson(customer.SLPRSNID); var state = _stateRepository.GetState(customer.STATE); var country = _countryRepository.GetCountry(customer.COUNTRY); var paymentTerm = _paymentTermRepository.GetPaymentTerm(customer.PYMTRMID); model.CustomerId = customer.CUSTNMBR; model.CustomerNumber = customer.CUSTNMBR; model.CustomerName = (!string.IsNullOrEmpty(customer.CUSTNAME.Replace(" ", string.Empty))) ? customer.CUSTNAME : "N/A"; model.ShortName = (!string.IsNullOrEmpty(customer.SHRTNAME.Replace(" ", string.Empty))) ? customer.SHRTNAME : "N/A"; model.SalespersonName = (dyanmicsSalesperson != null) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A"; model.SalesTerritoryDescription = (!string.IsNullOrEmpty(customer.SALSTERR.Replace(" ", string.Empty))) ? customer.SALSTERR : "N/A"; model.ContactName = (!string.IsNullOrEmpty(customer.CNTCPRSN)) ? customer.CNTCPRSN : "N/A"; model.ContactPhone = FormattingManager.FormatPhone(customer.PHONE1); model.FaxNumber = FormattingManager.FormatPhone(customer.FAX); model.Address1 = (!string.IsNullOrEmpty(customer.ADDRESS1)) ? customer.ADDRESS1 : "N/A"; model.City = (!string.IsNullOrEmpty(customer.CITY)) ? customer.CITY : "N/A"; model.StateName = (state != null) ? state.Name : "N/A"; model.CountryName = (country != null) ? country.Name : "N/A"; model.PostalCode = (!string.IsNullOrEmpty(customer.ZIP)) ? customer.ZIP : "N/A"; model.PaymentTermDescription = (paymentTerm != null && !string.IsNullOrEmpty(paymentTerm.Description)) ? paymentTerm.Description : "N/A"; model.IsActive = customer.INACTIVE != 1 ? true : false; if (_salespersonDynamicsRepository != null) { _salespersonDynamicsRepository.Dispose(); _salespersonDynamicsRepository = null; } if (_paymentTermRepository != null) { _paymentTermRepository.Dispose(); _paymentTermRepository = null; } if (_shipmentTermRepository != null) { _shipmentTermRepository.Dispose(); _shipmentTermRepository = null; } if (_stateRepository != null) { _stateRepository.Dispose(); _stateRepository = null; } if (_countryRepository != null) { _countryRepository.Dispose(); _countryRepository = null; } return(model); }
/// <summary> /// convert rfq to view model /// </summary> /// <param name="rfq"></param> /// <returns></returns> public RfqViewModel ConvertToView(Rfq rfq) { RfqViewModel model = new RfqViewModel(); var _projectRepository = new ProjectRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _salespersonDynamicsRepository = new SalespersonDynamicsRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _countryRepository = new CountryRepository(); var _shipmentTermRepository = new ShipmentTermRepository(); var _coatingTypeRepository = new CoatingTypeRepository(); var _specificationMaterialRepository = new SpecificationMaterialRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _projectPartRepository = new ProjectPartRepository(); var project = _projectRepository.GetProject(rfq.ProjectId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(rfq.CustomerId); var dyanmicsSalesperson = _salespersonDynamicsRepository.GetSalesperson((dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SLPRSNID)) ? dynamicsCustomer.SLPRSNID : string.Empty); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(rfq.FoundryId); var country = _countryRepository.GetCountry(rfq.CountryId); var shipmentTerm = _shipmentTermRepository.GetShipmentTerm(rfq.ShipmentTermId); var coatingType = _coatingTypeRepository.GetCoatingType(rfq.CoatingTypeId); var specificationMaterial = _specificationMaterialRepository.GetSpecificationMaterial(rfq.SpecificationMaterialId); var quotePriceSheet = _priceSheetRepository.GetQuotePriceSheetByRfq(rfq.RfqId); var productionPriceSheet = _priceSheetRepository.GetProductionPriceSheetBrRfq(rfq.RfqId); model.RfqId = rfq.RfqId; model.ProjectId = rfq.ProjectId; model.ProjectName = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A"; model.RfqNumber = (!string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.RfqDate = rfq.RfqDate; model.RfqDateStr = rfq.RfqDate.ToShortDateString(); model.CustomerId = rfq.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.FoundryId = rfq.FoundryId; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.CountryId = rfq.CountryId; model.SalespersonId = rfq.SalespersonId; model.SalespersonName = (dyanmicsSalesperson != null) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A"; model.CoatingTypeId = rfq.CoatingTypeId; model.SpecificationMaterialId = rfq.SpecificationMaterialId; model.ContactName = rfq.ContactName; model.CountryName = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A"; model.Attention = (!string.IsNullOrEmpty(rfq.Attention)) ? rfq.Attention : "N/A"; model.PrintsSent = (rfq.PrintsSent != null) ? rfq.PrintsSent.Value.ToShortDateString() : "N/A"; model.SentVia = rfq.SentVia; model.ShipmentTermDescription = (shipmentTerm != null) ? shipmentTerm.Description : "N/A"; model.IsMachined = rfq.IsMachined; model.Packaging = rfq.Packaging; model.NumberOfSamples = rfq.NumberOfSamples; model.Details = (!string.IsNullOrEmpty(rfq.Attention)) ? rfq.Details : "N/A"; model.CoatingType = (coatingType != null && !string.IsNullOrEmpty(coatingType.Description)) ? coatingType.Description : "N/A"; model.CoatingTypeId = rfq.CoatingTypeId; model.SpecificationMaterialId = rfq.SpecificationMaterialId; model.SpecificationMaterialDescription = (specificationMaterial != null && !string.IsNullOrEmpty(specificationMaterial.Description)) ? specificationMaterial.Description : "N/A"; model.ISIRRequired = rfq.ISIRRequired; model.SampleCastingAvailable = rfq.SampleCastingAvailable; model.MetalCertAvailable = rfq.MetalCertAvailable; model.CMTRRequired = rfq.CMTRRequired; model.GaugingRequired = rfq.GaugingRequired; model.TestBarsRequired = rfq.TestBarsRequired; model.Notes = (!string.IsNullOrEmpty(rfq.Notes)) ? rfq.Notes : "N/A"; model.IsOpen = rfq.IsOpen; model.IsHold = rfq.IsHold; model.HoldExpirationDate = (rfq.HoldExpirationDate != null) ? rfq.HoldExpirationDate : DateTime.MinValue; model.HoldExpirationDateStr = (rfq.HoldExpirationDate != null) ? rfq.HoldExpirationDate.Value.ToShortDateString() : "N/A"; model.HoldNotes = (!string.IsNullOrEmpty(rfq.HoldNotes)) ? rfq.HoldNotes : "N/A"; model.IsCanceled = rfq.IsCanceled; model.CanceledDate = (rfq.CanceledDate != null) ? rfq.CanceledDate : DateTime.MinValue; model.CanceledDateStr = (rfq.CanceledDate != null) ? rfq.CanceledDate.Value.ToShortDateString() : "N/A"; model.Status = rfq.IsOpen ? "Open" : rfq.IsCanceled ? "Canceled" : rfq.IsHold ? "On Hold" : "N/A"; model.QuotePriceSheetId = (quotePriceSheet != null) ? quotePriceSheet.PriceSheetId : Guid.Empty; model.QuotePriceSheet = (quotePriceSheet != null) ? quotePriceSheet.Number : "N/A"; model.ProductionPriceSheet = (productionPriceSheet != null) ? productionPriceSheet.Number : "N/A"; model.MaterialId = rfq.MaterialId; model.ShipmentTermId = rfq.ShipmentTermId; model.CancelNotes = (!string.IsNullOrEmpty(rfq.CancelNotes)) ? rfq.CancelNotes : "N/A"; model.HasPriceSheet = (quotePriceSheet != null || productionPriceSheet != null) ? true : false; model.RfqParts = new List <RfqPartViewModel>(); var rfqParts = _projectPartRepository.GetProjectParts().Where(x => x.RfqId == rfq.RfqId).ToList(); foreach (var rfqPart in rfqParts) { var rfqPartModel = new RfqPartConverter().ConvertToView(rfqPart); model.RfqParts.Add(rfqPartModel); } if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_salespersonDynamicsRepository != null) { _salespersonDynamicsRepository.Dispose(); _salespersonDynamicsRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_countryRepository != null) { _countryRepository.Dispose(); _countryRepository = null; } if (_shipmentTermRepository != null) { _shipmentTermRepository.Dispose(); _shipmentTermRepository = null; } if (_coatingTypeRepository != null) { _coatingTypeRepository.Dispose(); _coatingTypeRepository = null; } if (_specificationMaterialRepository != null) { _specificationMaterialRepository.Dispose(); _specificationMaterialRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } return(model); }