示例#1
0
        /// <summary>
        /// convert quote to view model
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public QuoteViewModel ConvertToView(Quote quote)
        {
            QuoteViewModel model = new QuoteViewModel();

            var _rfqRepository = new RfqRepository();
            var _customerDynamicsRepository        = new CustomerDynamicsRepository();
            var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository();
            var _stateRepository        = new StateRepository();
            var _shipmentTermRepository = new ShipmentTermRepository();
            var _paymentTermRepository  = new PaymentTermRepository();
            var _materialRepository     = new MaterialRepository();
            var _coatingTypeRepository  = new CoatingTypeRepository();
            var _htsNumberRepository    = new HtsNumberRepository();
            var _projectReposiotry      = new ProjectPartRepository();

            var rfq = _rfqRepository.GetRfq(quote.RfqId);
            var dynamicsCustomer        = _customerDynamicsRepository.GetCustomer(quote.CustomerId);
            var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(quote.CustomerAddressId);
            var state        = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty);
            var stateName    = (state != null) ? ", " + state.Name : string.Empty;
            var shipmentTerm = _shipmentTermRepository.GetShipmentTerm(quote.ShipmentTermId);
            var paymentTerm  = _paymentTermRepository.GetPaymentTerm(quote.PaymentTermId);
            var material     = _materialRepository.GetMaterial(quote.MaterialId);
            var coatingType  = _coatingTypeRepository.GetCoatingType(quote.CoatingTypeId);
            var htsNumber    = _htsNumberRepository.GetHtsNumber(quote.HtsNumberId);
            var quoteParts   = _projectReposiotry.GetProjectParts().Where(x => x.QuoteId == quote.QuoteId).ToList();

            model.QuoteId                 = quote.QuoteId;
            model.RfqId                   = quote.RfqId;
            model.PriceSheetId            = quote.PriceSheetId;
            model.ProjectId               = quote.ProjectId;
            model.QuoteNumber             = (!string.IsNullOrEmpty(quote.Number)) ? quote.Number : "N/A";
            model.QuoteDate               = quote.QuoteDate;
            model.QuoteDateStr            = quote.QuoteDate.ToShortDateString();
            model.RfqNumber               = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A";
            model.Validity                = quote.Validity;
            model.ContactName             = (!string.IsNullOrEmpty(quote.ContactName)) ? quote.ContactName : "N/A";
            model.CustomerId              = quote.CustomerId;
            model.CustomerName            = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CustomerAddressId       = quote.CustomerAddressId;
            model.CustomerAddress         = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " + dynamicsCustomerAddress.CITY + stateName : "N/A";
            model.ContactCopy             = (!string.IsNullOrEmpty(quote.ContactCopy)) ? quote.ContactCopy : "N/A";
            model.ShipmentTermId          = quote.ShipmentTermId;
            model.ShipmentTermDescription = (shipmentTerm != null && !string.IsNullOrEmpty(shipmentTerm.Description)) ? shipmentTerm.Description : "N/A";
            model.PaymentTermId           = quote.PaymentTermId;
            model.PaymentTermDescription  = (paymentTerm != null && !string.IsNullOrEmpty(paymentTerm.Description)) ? paymentTerm.Description : "N/A";
            model.MinimumShipment         = (!string.IsNullOrEmpty(quote.MinimumShipment)) ? quote.MinimumShipment : "N/A";
            model.ToolingTermDescription  = (!string.IsNullOrEmpty(quote.ToolingTermDescription)) ? quote.ToolingTermDescription : "N/A";
            model.SampleLeadTime          = (!string.IsNullOrEmpty(quote.SampleLeadTime)) ? quote.SampleLeadTime : "N/A";
            model.ProductionLeadTime      = (!string.IsNullOrEmpty(quote.ProductionLeadTime)) ? quote.ProductionLeadTime : "N/A";
            model.MaterialId              = quote.MaterialId;
            model.MaterialDescription     = (material != null && !string.IsNullOrEmpty(material.Description)) ? material.Description : "N/A";
            model.CoatingTypeId           = quote.CoatingTypeId;
            model.CoatingTypeDescription  = (coatingType != null && !string.IsNullOrEmpty(coatingType.Description)) ? coatingType.Description : "N/A";
            model.HtsNumberId             = quote.HtsNumberId;
            model.HtsNumberDescription    = (htsNumber != null && !string.IsNullOrEmpty(htsNumber.Description)) ? htsNumber.Description + "(" + (htsNumber.DutyRate * 100).ToString() + "%)" : "N/A";
            model.IsMachined              = quote.IsMachined;
            model.Notes                   = quote.Notes;
            model.IsOpen                  = quote.IsOpen;
            model.IsHold                  = quote.IsHold;
            model.HoldExpirationDate      = (quote.HoldExpirationDate != null) ? quote.HoldExpirationDate : DateTime.MinValue;
            model.HoldExpirationDateStr   = (quote.HoldExpirationDate != null) ? quote.HoldExpirationDate.Value.ToShortDateString() : null;
            model.HoldNotes               = (!string.IsNullOrEmpty(quote.HoldNotes)) ? quote.HoldNotes : "N/A";
            model.IsCanceled              = quote.IsCanceled;
            model.CanceledDate            = (quote.CanceledDate != null) ? quote.CanceledDate : DateTime.MinValue;
            model.CanceledDateStr         = (quote.CanceledDate != null) ? quote.CanceledDate.Value.ToShortDateString() : null;
            model.CancelNotes             = (!string.IsNullOrEmpty(quote.CancelNotes)) ? quote.CancelNotes : "N/A";
            model.Status                  = quote.IsOpen ? "Open" : quote.IsCanceled ? "Canceled" : quote.IsHold ? "On Hold" : "N/A";
            model.Machining               = quote.IsMachined == true ? "Included" : "Not Included";

            if (quoteParts != null)
            {
                model.QuoteParts = new List <QuotePartViewModel>();
                foreach (var quotePart in quoteParts)
                {
                    var quotePartModel = new QuotePartConverter().ConvertToView(quotePart);
                    model.QuoteParts.Add(quotePartModel);
                }
            }

            if (_rfqRepository != null)
            {
                _rfqRepository.Dispose();
                _rfqRepository = null;
            }

            if (_customerDynamicsRepository != null)
            {
                _customerDynamicsRepository.Dispose();
                _customerDynamicsRepository = null;
            }

            if (_customerAddressDynamicsRepository != null)
            {
                _customerAddressDynamicsRepository.Dispose();
                _customerAddressDynamicsRepository = null;
            }

            if (_stateRepository != null)
            {
                _stateRepository.Dispose();
                _stateRepository = null;
            }

            if (_shipmentTermRepository != null)
            {
                _shipmentTermRepository.Dispose();
                _shipmentTermRepository = null;
            }

            if (_paymentTermRepository != null)
            {
                _paymentTermRepository.Dispose();
                _paymentTermRepository = null;
            }

            if (_materialRepository != null)
            {
                _materialRepository.Dispose();
                _materialRepository = null;
            }

            if (_coatingTypeRepository != null)
            {
                _coatingTypeRepository.Dispose();
                _coatingTypeRepository = null;
            }

            if (_htsNumberRepository != null)
            {
                _htsNumberRepository.Dispose();
                _htsNumberRepository = null;
            }

            if (_projectReposiotry != null)
            {
                _projectReposiotry.Dispose();
                _projectReposiotry = null;
            }

            return(model);
        }
示例#2
0
        /// <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);
        }