Example #1
0
 public void Dispose()
 {
     if (_countryRepository != null)
     {
         _countryRepository.Dispose();
     }
 }
Example #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         repo.Dispose(disposing);
     }
     base.Dispose(disposing);
 }
Example #3
0
        /// <summary>
        /// convert foundry to view model
        /// </summary>
        /// <param name="foundry"></param>
        /// <returns></returns>
        public FoundryViewModel ConvertToView(PM00200_Foundry foundry)
        {
            FoundryViewModel model = new FoundryViewModel();

            var _paymentTermRepository  = new PaymentTermRepository();
            var _shipmentTermRepository = new ShipmentTermRepository();
            var _stateRepository        = new StateRepository();
            var _countryRepository      = new CountryRepository();

            var state       = _stateRepository.GetState(foundry.STATE);
            var country     = _countryRepository.GetCountry(foundry.COUNTRY);
            var paymentTerm = _paymentTermRepository.GetPaymentTerm(foundry.PYMTRMID);

            model.FoundryId              = foundry.VENDORID;
            model.VendorId               = foundry.VENDORID;
            model.ShortName              = (!string.IsNullOrEmpty(foundry.VENDSHNM.Replace(" ", string.Empty))) ? foundry.VENDSHNM : "N/A";
            model.ContactName            = (!string.IsNullOrEmpty(foundry.VNDCNTCT.Replace(" ", string.Empty))) ? foundry.VNDCNTCT : "N/A";
            model.ContactPhone           = FormattingManager.FormatPhone(foundry.PHNUMBR1);
            model.FaxNumber              = FormattingManager.FormatPhone(foundry.FAXNUMBR);
            model.Address1               = (!string.IsNullOrEmpty(foundry.ADDRESS1.Replace(" ", string.Empty))) ? foundry.ADDRESS1 : "N/A";
            model.Address2               = (!string.IsNullOrEmpty(foundry.ADDRESS2.Replace(" ", string.Empty))) ? foundry.ADDRESS2 : "N/A";
            model.Address3               = (!string.IsNullOrEmpty(foundry.ADDRESS3.Replace(" ", string.Empty))) ? foundry.ADDRESS3 : "N/A";
            model.City                   = (!string.IsNullOrEmpty(foundry.CITY.Replace(" ", string.Empty))) ? foundry.CITY : "N/A";
            model.StateName              = (state != null && !string.IsNullOrEmpty(state.Name)) ? state.Name : "N/A";
            model.PostalCode             = (!string.IsNullOrEmpty(foundry.ZIPCODE.Replace(" ", string.Empty))) ? foundry.ZIPCODE : "N/A";
            model.CountryName            = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.PaymentTermDescription = (paymentTerm != null && !string.IsNullOrEmpty(paymentTerm.Description)) ? paymentTerm.Description : "N/A";
            model.IsActive               = foundry.VENDSTTS != 1 ? false : true;

            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);
        }
Example #4
0
        /// <summary>
        /// convert site to view model
        /// </summary>
        /// <param name="site"></param>
        /// <returns></returns>
        public SiteViewModel ConvertToView(IV40700_Site site)
        {
            SiteViewModel model = new SiteViewModel();

            var _stateRepository   = new StateRepository();
            var _countryRepository = new CountryRepository();

            var state   = _stateRepository.GetState(site.STATE);
            var country = _countryRepository.GetCountry(site.COUNTRY);

            model.SiteId          = site.LOCNCODE;
            model.LocationCode    = site.LOCNCODE;
            model.SiteDescription = (!string.IsNullOrEmpty(site.LOCNDSCR.Replace(" ", string.Empty))) ? site.LOCNDSCR : "N/A";
            model.Address1        = (!string.IsNullOrEmpty(site.ADDRESS1.Replace(" ", string.Empty))) ? site.ADDRESS1 : "N/A";
            model.Address2        = (!string.IsNullOrEmpty(site.ADDRESS2.Replace(" ", string.Empty))) ? site.ADDRESS2 : "N/A";
            model.Address3        = (!string.IsNullOrEmpty(site.ADDRESS3.Replace(" ", string.Empty))) ? site.ADDRESS3 : "N/A";
            model.City            = (!string.IsNullOrEmpty(site.CITY.Replace(" ", string.Empty))) ? site.CITY : "N/A";
            model.StateName       = (state != null && !string.IsNullOrEmpty(state.Name)) ? state.Name : "N/A";
            model.PostalCode      = (!string.IsNullOrEmpty(site.ZIPCODE.Replace(" ", string.Empty))) ? site.ZIPCODE : "N/A";
            model.CountryName     = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.IsActive        = site.INACTIVE != 1 ? true : false;

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

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

            return(model);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <summary>
        /// convert customer address to customer view model
        /// </summary>
        /// <param name="customerAddress"></param>
        /// <returns></returns>
        public CustomerViewModel ConvertToView(RM00102_CustomerAddress customerAddress)
        {
            CustomerViewModel model = new CustomerViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _stateRepository            = new StateRepository();
            var _countryRepository          = new CountryRepository();
            var _siteDynamicsRepository     = new SiteDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(customerAddress.CUSTNMBR);
            var state            = _stateRepository.GetState(customerAddress.STATE);
            var country          = _countryRepository.GetCountry(customerAddress.COUNTRY);
            var dynamicsSite     = _siteDynamicsRepository.GetSite(customerAddress.LOCNCODE);

            var type = (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.PRBTADCD.Replace(" ", string.Empty))) ?
                       "Bill To Address" : (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.PRSTADCD.Replace(" ", string.Empty))) ?
                       "Ship To Address" : (dynamicsCustomer != null && customerAddress.ADRSCODE.Replace(" ", string.Empty).Equals(dynamicsCustomer.STADDRCD.Replace(" ", string.Empty))) ?
                       "Standard Address" : "N/A";

            model.CustomerAddressId = customerAddress.ADRSCODE;
            model.CustomerNumber    = customerAddress.CUSTNMBR;
            model.ShortName         = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.AddressCode       = customerAddress.ADRSCODE;
            model.AddressType       = type;
            model.ContactName       = (!string.IsNullOrEmpty(customerAddress.CNTCPRSN.Replace(" ", string.Empty))) ? customerAddress.CNTCPRSN : "N/A";
            model.ContactPhone      = FormattingManager.FormatPhone(customerAddress.PHONE1);
            model.FaxNumber         = FormattingManager.FormatPhone(customerAddress.FAX);
            model.Address1          = (!string.IsNullOrEmpty(customerAddress.ADDRESS1.Replace(" ", string.Empty))) ? customerAddress.ADDRESS1 : "N/A";
            model.Address2          = (!string.IsNullOrEmpty(customerAddress.ADDRESS2.Replace(" ", string.Empty))) ? customerAddress.ADDRESS2 : "N/A";
            model.Address3          = (!string.IsNullOrEmpty(customerAddress.ADDRESS3.Replace(" ", string.Empty))) ? customerAddress.ADDRESS3 : "N/A";
            model.City            = (!string.IsNullOrEmpty(customerAddress.CITY.Replace(" ", string.Empty))) ? customerAddress.CITY : "N/A";
            model.StateName       = (state != null && !string.IsNullOrEmpty(state.Name)) ? state.Name : "N/A";
            model.PostalCode      = (!string.IsNullOrEmpty(customerAddress.ZIP.Replace(" ", string.Empty))) ? customerAddress.ZIP : "N/A";
            model.CountryName     = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.ShippingMethod  = (!string.IsNullOrEmpty(customerAddress.SHIPMTHD.Replace(" ", string.Empty))) ? customerAddress.SHIPMTHD : "N/A";
            model.SiteDescription = (dynamicsSite != null && !string.IsNullOrEmpty(dynamicsSite.LOCNDSCR.Replace(" ", string.Empty))) ? dynamicsSite.LOCNDSCR : "N/A";

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

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

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

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

            return(model);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        public static CountryResponse GetAllCountries()
        {
            var response = new CountryResponse();
            var countryRepository = new CountryRepository();
            try
            {
                var listCountries = countryRepository.Query().Where(x => x.is_active == 1).ToList();
                foreach (var country in listCountries)
                {
                    countryRepository.Detach(country);
                    response.Countries.Add(AutoMapper.Mapper.Map<country, countryDto>(country));

                }
            }
            catch (InvalidOperationException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (ArgumentNullException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (NullReferenceException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (UpdateException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            finally
            {
                countryRepository.Dispose();
            }

            return response;
        }
Example #9
0
        public static CountryResponse AddCountry(CountryRequest request)
        {
            var response = new CountryResponse();
            var countryRepository = new CountryRepository();
            try
            {
                var newCountry = new country
                                  {
                                      country_name = request.CountryName,
                                      created_date = DateTime.Now,
                                      modified_date = DateTime.Now,
                                      modified_by = request.ModifiedBy
                                  };
                countryRepository.Add(newCountry);
                countryRepository.SaveChanges();
            }
            catch (InvalidOperationException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (ArgumentNullException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (NullReferenceException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (OptimisticConcurrencyException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            catch (UpdateException exc)
            {
                log.Error(exc);
                response.Message = exc.Message;
                response.Acknowledge = AcknowledgeType.FAILURE;
            }
            finally
            {
                countryRepository.Dispose();
            }

            return response;
        }
Example #10
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);
        }
Example #11
0
        /// <summary>
        /// convert rfq view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Rfq ConvertToDomain(RfqViewModel model)
        {
            Rfq rfq = new Rfq();

            var _countryRepository               = new CountryRepository();
            var _projectRepository               = new ProjectRepository();
            var _coatingTypeRepository           = new CoatingTypeRepository();
            var _specificationMaterialRepository = new SpecificationMaterialRepository();

            var project               = _projectRepository.GetProject((model.ProjectName != null && model.ProjectName != null && model.ProjectName != string.Empty) ? model.ProjectName : "N/A");
            var coatingType           = _coatingTypeRepository.GetCoatingType((model.CoatingType != null && model.CoatingType != null && model.CoatingType != string.Empty) ? model.CoatingType : "N/A");
            var specificationMaterial = _specificationMaterialRepository.GetSpecificationMaterial((model.SpecificationMaterialDescription != null && model.SpecificationMaterialDescription != null && model.SpecificationMaterialDescription != string.Empty) ? model.SpecificationMaterialDescription : "N/A");

            rfq.RfqId                   = model.RfqId;
            rfq.Number                  = model.RfqNumber;
            rfq.RfqDate                 = model.RfqDate;
            rfq.ProjectId               = (project != null) ? project.ProjectId : Guid.Empty;
            rfq.CustomerId              = model.CustomerId;
            rfq.SalespersonId           = model.SalespersonId;
            rfq.FoundryId               = model.FoundryId;
            rfq.ContactName             = model.ContactName;
            rfq.CountryId               = model.CountryId;
            rfq.Attention               = model.Attention;
            rfq.PrintsSent              = DateTime.Parse(model.PrintsSent);
            rfq.SentVia                 = model.SentVia;
            rfq.ShipmentTermId          = model.ShipmentTermId;
            rfq.IsMachined              = model.IsMachined;
            rfq.Packaging               = model.Packaging;
            rfq.NumberOfSamples         = model.NumberOfSamples;
            rfq.Details                 = model.Details;
            rfq.CoatingTypeId           = (coatingType != null) ? coatingType.CoatingTypeId : Guid.Empty;
            rfq.SpecificationMaterialId = (specificationMaterial != null) ? specificationMaterial.SpecificationMaterialId : Guid.Empty;
            rfq.MaterialId              = model.MaterialId;
            rfq.ISIRRequired            = model.ISIRRequired;
            rfq.SampleCastingAvailable  = model.SampleCastingAvailable;
            rfq.MetalCertAvailable      = model.MetalCertAvailable;
            rfq.CMTRRequired            = model.CMTRRequired;
            rfq.GaugingRequired         = model.GaugingRequired;
            rfq.TestBarsRequired        = model.TestBarsRequired;
            rfq.Notes                   = model.Notes;
            rfq.IsOpen                  = model.IsOpen;
            rfq.IsHold                  = model.IsHold;
            rfq.IsCanceled              = model.IsCanceled;
            rfq.HoldExpirationDate      = (model.IsHold) ? model.HoldExpirationDate : null;
            rfq.HoldNotes               = (model.IsHold) ? model.HoldNotes : null;
            rfq.CanceledDate            = (model.IsCanceled) ? model.CanceledDate : null;
            rfq.CancelNotes             = (model.IsCanceled) ? model.CancelNotes : null;

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

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

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

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

            return(rfq);
        }