/// <summary> /// convert price sheet part to view model for quote price sheet /// </summary> /// <param name="part"></param> /// <returns></returns> public PriceSheetPartViewModel ConvertToProjectPartView(PriceSheetPart part) { PriceSheetPartViewModel model = new PriceSheetPartViewModel(); var _projectPartRepository = new ProjectPartRepository(); var _priceSheetRepository = new PriceSheetRepository(); var priceSheet = _priceSheetRepository.GetPriceSheet(part.PriceSheetId); var projectPart = _projectPartRepository.GetProjectPart(part.ProjectPartId); model.ProjectPartId = part.ProjectPartId ?? Guid.Empty; model.PriceSheetPartId = part.PriceSheetPartId; model.PriceSheetId = part.PriceSheetId; model.PriceSheetNumber = (priceSheet != null) ? priceSheet.Number : "N/A"; model.PartNumber = (projectPart != null) ? projectPart.Number : "N/A"; model.PartDescription = (projectPart != null) ? projectPart.Description : "N/A"; model.AvailableQuantity = part.AvailableQuantity; model.CustomerOrderQuantity = part.AvailableQuantity; model.UnitPrice = part.Price; model.UnitCost = part.Cost; if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } return(model); }
/// <summary> /// convert rfq to quote view model /// </summary> /// <param name="rfq"></param> /// <returns></returns> public QuoteViewModel ConvertToView(Rfq rfq) { QuoteViewModel model = new QuoteViewModel(); var _priceSheetRepository = new PriceSheetRepository(); var _projectPartRepository = new ProjectPartRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(rfq.CustomerId); var priceSheet = _priceSheetRepository.GetPriceSheets().FirstOrDefault(x => x.RfqId == rfq.RfqId && x.IsQuote); var projectParts = _projectPartRepository.GetProjectParts().Where(x => x.PriceSheetId == ((priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty)); model.ProjectId = rfq.ProjectId; model.RfqId = rfq.RfqId; model.RfqNumber = rfq.Number; model.ContactName = rfq.ContactName; model.CustomerId = rfq.CustomerId; model.CustomerName = (dynamicsCustomer != null) ? dynamicsCustomer.SHRTNAME : "N/A"; model.MaterialId = rfq.MaterialId; model.CoatingTypeId = rfq.CoatingTypeId; model.IsMachined = rfq.IsMachined; model.Machining = rfq.IsMachined ? "Included" : "Not Included"; model.PriceSheetId = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty; model.Date = DateTime.Now.ToShortDateString(); model.QuoteDateStr = DateTime.Now.ToShortDateString(); if (projectParts != null && projectParts.Count() > 0) { model.MaterialId = projectParts.FirstOrDefault().MaterialId; model.QuoteParts = new List <QuotePartViewModel>(); foreach (var projectPart in projectParts) { var quotePartModel = new QuotePartConverter().ConvertToView(projectPart); model.QuoteParts.Add(quotePartModel); } } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } return(model); }
/// <summary> /// convert customer order part to project part view model /// </summary> /// <param name="customerOrderPart"></param> /// <returns></returns> public CustomerOrderPartViewModel ConvertToProjectPartView(CustomerOrderPart customerOrderPart) { CustomerOrderPartViewModel model = new CustomerOrderPartViewModel(); var _priceSheetRepository = new PriceSheetRepository(); var _projectPartRepository = new ProjectPartRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var priceSheetPart = _priceSheetRepository.GetPriceSheetPart(customerOrderPart.PriceSheetPartId); var projectPart = _projectPartRepository.GetProjectPart((customerOrderPart.ProjectPartId != null) ? customerOrderPart.ProjectPartId : Guid.Empty); var priceSheet = _priceSheetRepository.GetPriceSheet((priceSheetPart != null) ? priceSheetPart.PriceSheetId : Guid.Empty); var customerOrder = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId); var receivedQuantity = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.CustomerOrderPartId == customerOrderPart.CustomerOrderPartId && x.HasBeenReceived).Select(y => y.ReceiptQuantity).Sum(); model.CustomerOrderPartId = customerOrderPart.CustomerOrderPartId; model.CustomerOrderId = customerOrderPart.CustomerOrderId; model.PONumber = (!string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A"; model.ProjectPartId = customerOrderPart.ProjectPartId; model.PriceSheetPartId = customerOrderPart.PriceSheetPartId; model.PriceSheetId = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty; model.AvailableQuantity = customerOrderPart.AvailableQuantity; model.CustomerOrderQuantity = customerOrderPart.Quantity; model.PartNumber = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A"; model.PartDescription = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "N/A"; model.PriceSheetNumber = (priceSheet != null && !string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A"; model.EstArrivalDate = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.ReceiptQuantity = receivedQuantity; model.Cost = customerOrderPart.Cost; model.Price = customerOrderPart.Price; if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } return(model); }
/// <summary> /// convert price sheet part to view model for production price sheet /// </summary> /// <param name="part"></param> /// <returns></returns> public PriceSheetPartViewModel ConvertToPartView(PriceSheetPart part) { PriceSheetPartViewModel model = new PriceSheetPartViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _projectPartRepository = new ProjectPartRepository(); var priceSheet = _priceSheetRepository.GetPriceSheet(part.PriceSheetId); var projectPart = _projectPartRepository.GetProjectPart(part.ProjectPartId); var tempPart = _partRepository.GetPart((projectPart != null) ? projectPart.PartId : null); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((tempPart != null) ? tempPart.Number : null); model.ProjectPartId = part.ProjectPartId ?? Guid.Empty; model.PartId = (tempPart != null) ? tempPart.PartId : Guid.Empty; model.PriceSheetPartId = part.PriceSheetPartId; model.PriceSheetId = part.PriceSheetId; model.PriceSheetNumber = (priceSheet != null) ? priceSheet.Number : "N/A"; model.PartNumber = (tempPart != null) ? tempPart.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.AvailableQuantity = part.AvailableQuantity; model.CustomerOrderQuantity = part.AvailableQuantity; model.UnitPrice = part.Price; model.UnitCost = part.Cost; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } return(model); }
/// <summary> /// convert price sheet to view model /// </summary> /// <param name="priceSheet"></param> /// <returns></returns> public PriceSheetViewModel ConvertToView(PriceSheet priceSheet) { PriceSheetViewModel model = new PriceSheetViewModel(); var _projectRepository = new ProjectRepository(); var _rfqRepository = new RfqRepository(); var _countryRepository = new CountryRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _quoteRepository = new QuoteRepository(); var project = _projectRepository.GetProject(priceSheet.ProjectId); var rfq = _rfqRepository.GetRfq(priceSheet.RfqId); var country = _countryRepository.GetCountry((rfq != null) ? rfq.CountryId : Guid.Empty); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry((rfq != null) ? rfq.FoundryId : string.Empty); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer((rfq != null) ? rfq.CustomerId : string.Empty); model.PriceSheetId = priceSheet.PriceSheetId; model.Number = (!string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A"; model.RfqId = priceSheet.RfqId; model.ProjectMargin = priceSheet.ProjectMargin; model.ProjectName = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A"; model.RfqNumber = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.Country = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A"; model.Foundry = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.Customer = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.WAF = priceSheet.WAF; model.AnnualContainer = priceSheet.AnnualContainer; model.AnnualDollars = priceSheet.AnnualDollars; model.AnnualMargin = priceSheet.AnnualMargin; model.AnnualWeight = priceSheet.AnnualWeight; model.DollarContainer = priceSheet.DollarContainer; model.InsuranceDivisor = priceSheet.InsuranceDivisor; model.InsuranceDuty = priceSheet.InsuranceDuty; model.InsuranceFreight = priceSheet.InsuranceFreight; model.InsurancePercentage = priceSheet.InsurancePercentage; model.InsurancePremium = priceSheet.InsurancePremium; model.ToolingMargin = priceSheet.ToolingMargin; model.FixtureMargin = priceSheet.FixtureMargin; model.DueDate = priceSheet.ModifiedDate; model.PriceSheetType = priceSheet.IsQuote ? "Quote" : priceSheet.IsProduction ? "Production" : "N/A"; model.TotalWeight = priceSheet.AnnualWeight; model.PriceSheetParts = new List <PriceSheetPartViewModel>(); model.CostDetailList = new List <PriceSheetCostDetailViewModel>(); model.PriceDetailList = new List <PriceSheetPriceDetailViewModel>(); var priceSheetParts = _priceSheetRepository.GetPriceSheetParts(priceSheet.PriceSheetId).ToList(); if (priceSheetParts != null && priceSheetParts.Count > 0) { foreach (var priceSheetPart in priceSheetParts) { PriceSheetPartViewModel priceSheetPartModel = new PriceSheetPartViewModel(); if (priceSheet.IsQuote) { priceSheetPartModel = new PriceSheetPartConverter().ConvertToProjectPartView(priceSheetPart); } else if (priceSheet.IsProduction) { priceSheetPartModel = new PriceSheetPartConverter().ConvertToPartView(priceSheetPart); } model.PriceSheetParts.Add(priceSheetPartModel); PriceSheetCostDetailViewModel costDetail = new PriceSheetPartConverter().ConvertToCostView(priceSheetPart); model.CostDetailList.Add(costDetail); var priceDetail = new PriceSheetPartConverter().ConvertToPriceView(priceSheetPart); model.PriceDetailList.Add(priceDetail); model.TotalAnnualCost += costDetail.AnnualCost; model.TotalAnnualPrice += priceDetail.AnnualPrice; model.PriceSheetParts = model.PriceSheetParts.OrderBy(y => y.PartNumber).ToList(); var margin = (model.TotalAnnualPrice - model.TotalAnnualCost) / model.TotalAnnualPrice * 100; model.OverallMargin = margin.ToString("#.##") + '%'; } } model.BucketList = _priceSheetRepository.GetPriceSheetBuckets().Where(x => x.PriceSheetId == priceSheet.PriceSheetId).ToList(); var quotes = _quoteRepository.GetQuotes(); if (quotes != null && quotes.Count > 0) { foreach (var quote in quotes) { if (quote.PriceSheetId == priceSheet.PriceSheetId) { model.NoEdit = true; break; } } } if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_countryRepository != null) { _countryRepository.Dispose(); _countryRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_quoteRepository != null) { _quoteRepository.Dispose(); _quoteRepository = null; } return(model); }
/// <summary> /// convert customer order to view model /// </summary> /// <param name="order"></param> /// <returns></returns> public CustomerOrderViewModel ConvertToView(CustomerOrder order) { CustomerOrderViewModel model = new CustomerOrderViewModel(); var _projectRepository = new ProjectRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository(); var _stateRepository = new StateRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _siteDynamicsRepository = new SiteDynamicsRepository(); var _orderTermRepository = new OrderTermRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var project = _projectRepository.GetProject(order.ProjectId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(order.CustomerId); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(order.FoundryId); var dynamicsAddress = _customerAddressDynamicsRepository.GetCustomerAddress(order.CustomerAddressId); var state = _stateRepository.GetState((dynamicsAddress != null && !string.IsNullOrEmpty(dynamicsAddress.STATE)) ? dynamicsAddress.STATE : string.Empty); var stateName = (state != null && !string.IsNullOrEmpty(state.Name)) ? ", " + state.Name : string.Empty; var dynamicsSite = _siteDynamicsRepository.GetSite((dynamicsAddress != null && !string.IsNullOrEmpty(dynamicsAddress.LOCNCODE)) ? dynamicsAddress.LOCNCODE : string.Empty); var orderTerm = _orderTermRepository.GetOrderTerm(order.ShipmentTermsId); var customerOrderParts = _customerOrderRepository.GetCustomerOrderParts().Where(x => x.CustomerOrderId == order.CustomerOrderId).ToList(); model.CustomerOrderId = order.CustomerOrderId; model.OrderDate = order.PODate; model.PONumber = (!string.IsNullOrEmpty(order.PONumber)) ? order.PONumber : "N/A"; model.PODate = order.PODate; model.PODateStr = (order.PODate != null) ? order.PODate.ToShortDateString() : "N/A"; model.ProjectId = order.ProjectId; model.ProjectName = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A"; model.CustomerId = order.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.CustomerAddressId = order.CustomerAddressId; model.CustomerAddress = (dynamicsAddress != null) ? dynamicsAddress.ADDRESS1 + " " + dynamicsAddress.CITY + stateName : "N/A"; model.FoundryId = order.FoundryId; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.SiteId = order.SiteId; model.SiteDescription = (dynamicsSite != null && !string.IsNullOrEmpty(dynamicsSite.LOCNDSCR)) ? dynamicsSite.LOCNDSCR : "N/A"; model.ShipmentTermsId = order.ShipmentTermsId; model.ShipmentTerms = (orderTerm != null && !string.IsNullOrEmpty(orderTerm.Description)) ? orderTerm.Description : "N/A"; model.PortDate = (order.PortDate != null) ? order.PortDate : DateTime.MinValue; model.PortDateStr = (order.PortDate != null) ? order.PortDate.Value.ToShortDateString() : "N/A"; model.ShipDate = (order.ShipDate != null) ? order.ShipDate : DateTime.MinValue; model.ShipDateStr = (order.ShipDate != null) ? order.ShipDate.Value.ToShortDateString() : "N/A"; model.DueDate = (order.DueDate != null) ? order.DueDate : DateTime.MinValue; model.DueDateStr = (order.DueDate != null) ? order.DueDate.Value.ToShortDateString() : "N/A"; model.EstArrivalDate = (order.EstArrivalDate != null) ? order.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (order.EstArrivalDate != null) ? order.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.OrderNotes = (!string.IsNullOrEmpty(order.Notes)) ? order.Notes : "N/A"; model.IsOpen = order.IsOpen; model.IsHold = order.IsHold; model.HoldExpirationDate = (order.HoldExpirationDate != null) ? order.HoldExpirationDate : DateTime.MinValue; model.HoldExpirationDateStr = (order.HoldExpirationDate != null) ? order.HoldExpirationDate.Value.ToShortDateString() : "N/A"; model.HoldNotes = (!string.IsNullOrEmpty(order.HoldNotes)) ? order.HoldNotes : "N/A"; model.IsCanceled = order.IsCanceled; model.CanceledDate = (order.CanceledDate != null) ? order.CanceledDate : DateTime.MinValue; model.CanceledDateStr = (order.CanceledDate != null) ? order.CanceledDate.Value.ToShortDateString() : "N/A"; model.CancelNotes = (!string.IsNullOrEmpty(order.CancelNotes)) ? order.CancelNotes : "N/A"; model.IsComplete = order.IsComplete; model.CompletedDate = (order.CompletedDate != null) ? order.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (order.CompletedDate != null) ? order.CompletedDate.Value.ToShortDateString() : "N/A"; model.Status = order.IsOpen ? "Open" : order.IsCanceled ? "Canceled" : order.IsComplete ? "Completed" : order.IsHold ? "On Hold" : "N/A"; model.IsSample = order.IsSample; model.IsTooling = order.IsTooling; model.IsProduction = order.IsProduction; model.OrderTypeDescription = order.IsSample ? "Sample" : order.IsTooling ? "Tooling" : order.IsProduction ? "Production" : "N/A"; model.CustomerOrderParts = new List <CustomerOrderPartViewModel>(); var totalPrice = 0.00m; if (customerOrderParts != null && customerOrderParts.Count > 0) { foreach (var customerOrderPart in customerOrderParts) { CustomerOrderPartViewModel partModel = new CustomerOrderPartViewModel(); if (model.OrderTypeDescription.Equals("Sample") || model.OrderTypeDescription.Equals("Tooling")) { partModel = new CustomerOrderPartConverter().ConvertToProjectPartView(customerOrderPart); } else { partModel = new CustomerOrderPartConverter().ConvertToPartView(customerOrderPart); } model.CustomerOrderParts.Add(partModel); totalPrice += (partModel.Price * partModel.CustomerOrderQuantity); } } model.TotalPrice = Math.Round(totalPrice, 2); model.CustomerOrderParts = model.CustomerOrderParts.OrderByDescending(y => y.EstArrivalDate).ThenBy(y => y.PartNumber).ToList(); if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_customerAddressDynamicsRepository != null) { _customerAddressDynamicsRepository.Dispose(); _customerAddressDynamicsRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_stateRepository != null) { _stateRepository.Dispose(); _stateRepository = null; } if (_siteDynamicsRepository != null) { _siteDynamicsRepository.Dispose(); _siteDynamicsRepository = null; } if (_orderTermRepository != null) { _orderTermRepository.Dispose(); _orderTermRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = 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); }