Beispiel #1
0
        /// <summary>
        /// convert price sheet to list model
        /// </summary>
        /// <param name="priceSheet"></param>
        /// <returns></returns>
        public PriceSheetListModel ConvertToListView(PriceSheet priceSheet)
        {
            PriceSheetListModel model = new PriceSheetListModel();

            var _rfqRepository = new RfqRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();

            var rfq = _rfqRepository.GetRfq(priceSheet.RfqId);
            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.Date          = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate : DateTime.MinValue;
            model.DateStr       = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate.Value.ToShortDateString() : "N/A";
            model.CustomerName  = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.RfqNumber     = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A";
            model.ProjectMargin = priceSheet.ProjectMargin;
            model.WAF           = priceSheet.WAF;
            model.Status        = priceSheet.IsQuote ? "Quote" : priceSheet.IsProduction ? "Production" : "N/A";
            model.CreatedDate   = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate : DateTime.MinValue;

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

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

            return(model);
        }
Beispiel #2
0
        /// <summary>
        /// convert accountCode to view model
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public AccountCodeViewModel ConvertToView(AccountCode code)
        {
            AccountCodeViewModel model = new AccountCodeViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _bucketRepository           = new BucketRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(code.CustomerId);
            var bucket           = _bucketRepository.GetBucket(code.AccountCodeId);

            model.AccountCodeId = code.AccountCodeId;
            model.Description   = (!string.IsNullOrEmpty(code.Description)) ? code.Description : "N/A";
            model.CustomerId    = code.CustomerId;
            model.CustomerName  = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.BucketName    = (bucket != null && !string.IsNullOrEmpty(bucket.Name)) ? bucket.Name : "N/A";

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

            return(model);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        /// convert debitMemo to list model
        /// </summary>
        /// <param name="memo"></param>
        /// <returns></returns>
        public DebitMemoViewModel ConvertToListView(DebitMemo memo)
        {
            DebitMemoViewModel model = new DebitMemoViewModel();

            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();
            var _foundryInvoiceRepository   = new FoundryInvoiceRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            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 creditMemo       = _creditMemoRepository.GetCreditMemoByDebitMemo(memo.DebitMemoId);

            model.DebitMemoId      = memo.DebitMemoId;
            model.CustomerId       = memo.CustomerId;
            model.FoundryId        = (dynamicsFoundry != null) ? dynamicsFoundry.VENDORID : "N/A";
            model.DebitMemoNumber  = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A";
            model.InvoiceNumber    = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A";
            model.FoundryName      = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.DebitMemoDate    = memo.DebitMemoDate;
            model.DebitMemoDateStr = memo.DebitMemoDate.ToShortDateString();
            model.DebitAmount      = memo.Amount;
            model.CustomerName     = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CreditMemoId     = (creditMemo != null) ? creditMemo.CreditMemoId : Guid.Empty;
            model.CreditMemoNumber = (creditMemo != null && !string.IsNullOrEmpty(creditMemo.Number)) ? creditMemo.Number : "N/A";
            model.IsOpen           = memo.IsOpen;
            model.IsClosed         = memo.IsClosed;
            model.CreatedDate      = (memo.CreatedDate != null) ? memo.CreatedDate : DateTime.MinValue;
            model.CreatedBy        = memo.CreatedBy;

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

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

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

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

            return(model);
        }
Beispiel #5
0
        /// <summary>
        /// convert packlingList to list model
        /// </summary>
        /// <param name="packingList"></param>
        /// <returns></returns>
        public PackingListViewModel ConvertToListView(PackingList packingList)
        {
            PackingListViewModel model = new PackingListViewModel();

            var _customerDynamicsRepository        = new CustomerDynamicsRepository();
            var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository();
            var _stateRepository   = new StateRepository();
            var _carrierRepository = new CarrierRepository();

            var dynamicsCustomer        = _customerDynamicsRepository.GetCustomer(packingList.CustomerId);
            var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(packingList.CustomerAddressId);
            var state     = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty);
            var stateName = (state != null && !string.IsNullOrEmpty(state.Name)) ? ", " + state.Name : string.Empty;
            var carrier   = _carrierRepository.GetCarrier(packingList.CarrierId);

            model.PackingListId   = packingList.PackingListId;
            model.CreatedDate     = (packingList.CreatedDate != null) ? packingList.CreatedDate : DateTime.MinValue;
            model.CreatedDateStr  = (packingList.CreatedDate != null) ? packingList.CreatedDate.Value.ToShortDateString() : "N/A";
            model.CustomerName    = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CustomerAddress = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " +
                                    dynamicsCustomerAddress.CITY + ", " + stateName : "N/A";
            model.ShipDate       = packingList.ShipDate;
            model.ShipDateStr    = packingList.ShipDate.ToShortDateString();
            model.CarrierName    = (carrier != null && !string.IsNullOrEmpty(carrier.Name)) ? carrier.Name : "N/A";
            model.TrackingNumber = (!string.IsNullOrEmpty(packingList.TrackingNumber)) ? packingList.TrackingNumber : "N/A";
            model.Notes          = (!string.IsNullOrEmpty(packingList.TrackingNumber)) ? packingList.Notes : "N/A";
            model.IsClosed       = packingList.IsClosed;
            model.ClosedDate     = (packingList.ClosedDate != null) ? packingList.ClosedDate : DateTime.MinValue;
            model.ClosedDateStr  = (packingList.ClosedDate != null) ? packingList.ClosedDate.Value.ToShortDateString() : "N/A";

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

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

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

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

            return(model);
        }
Beispiel #6
0
        /// <summary>
        /// convert project to list model
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public ProjectViewModel ConvertToListView(Project project)
        {
            ProjectViewModel model = new ProjectViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _rfqRepository             = new RfqRepository();
            var _foundryDynamicsRepository = new FoundryDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(project.CustomerId);
            var dynamicsFoundry  = _foundryDynamicsRepository.GetFoundry(project.FoundryId);

            model.ProjectId             = project.ProjectId;
            model.ProjectName           = (!string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A";
            model.CustomerId            = project.CustomerId;
            model.FoundryId             = project.FoundryId;
            model.CustomerName          = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.FoundryName           = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.CreatedDate           = (project.CreatedDate != null) ? project.CreatedDate : DateTime.MinValue;
            model.CreatedDateStr        = (project.CreatedDate != null) ? project.CreatedDate.Value.ToShortDateString() : "N/A";
            model.CreatedBy             = project.CreatedBy;
            model.IsOpen                = project.IsOpen;
            model.IsHold                = project.IsHold;
            model.HoldNotes             = project.HoldNotes;
            model.HoldExpirationDate    = (project.HoldExpirationDate != null) ? project.HoldExpirationDate : DateTime.MinValue;
            model.HoldExpirationDateStr = (project.HoldExpirationDate != null) ? project.HoldExpirationDate.Value.ToShortDateString() : "N/A";
            model.IsCanceled            = project.IsCanceled;
            model.CanceledDate          = (project.CanceledDate != null) ? project.CanceledDate : DateTime.MinValue;;
            model.CanceledDateStr       = (project.CanceledDate != null) ? project.CanceledDate.Value.ToString("M/dd/yyyy") : "N/A";
            model.IsComplete            = project.IsComplete;
            model.CompletedDate         = (project.CompletedDate != null) ? project.CompletedDate : DateTime.MinValue;
            model.CompletedDateStr      = (project.CompletedDate != null) ? project.CompletedDate.Value.ToString("M/dd/yyyy") : "N/A";
            model.Status                = project.IsOpen ? "Open" : project.IsCanceled ? "Canceled" : project.IsComplete ? "Completed" : project.IsHold ? "On Hold" : "N/A";

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

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

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

            return(model);
        }
Beispiel #7
0
        /// <summary>
        /// convert foudry order to list model
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public FoundryOrderViewModel ConvertToListView(FoundryOrder order)
        {
            FoundryOrderViewModel model = new FoundryOrderViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(order.CustomerId);
            var dynamicsFoundry  = _foundryDynamicsRepository.GetFoundry(order.FoundryId);

            model.FoundryOrderId       = order.FoundryOrderId;
            model.OrderNumber          = (!string.IsNullOrEmpty(order.Number)) ? order.Number : "N/A";
            model.CustomerName         = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.FoundryName          = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.DueDate              = (order.DueDate != null) ? order.DueDate : DateTime.MinValue;
            model.DueDateStr           = (order.DueDate != null) ? order.DueDate.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.IsConfirmed          = order.IsConfirmed;
            model.IsOpen               = order.IsOpen ? true : false;
            model.IsHold               = order.IsHold;
            model.IsCanceled           = order.IsCanceled;
            model.IsComplete           = order.IsComplete;
            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.CreatedDate          = (order.CreatedDate != null) ? order.CreatedDate : DateTime.MinValue;
            model.HoldExpirationDate   = order.HoldExpirationDate;
            model.HoldNotes            = order.HoldNotes;

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

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

            return(model);
        }
Beispiel #8
0
        /// <summary>
        /// convert order term to customer view model
        /// </summary>
        /// <param name="orderTerm"></param>
        /// <returns></returns>
        public CustomerViewModel ConvertToCustomerView(OrderTerm orderTerm)
        {
            CustomerViewModel model = new CustomerViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(orderTerm.CustomerId);

            model.OrderTermId           = orderTerm.OrderTermId;
            model.CustomerId            = orderTerm.CustomerId;
            model.CustomerName          = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.OrderTermsDescription = (!string.IsNullOrEmpty(orderTerm.Description)) ? orderTerm.Description : "N/A";

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

            return(model);
        }
Beispiel #9
0
        /// <summary>
        /// convert tracking code to view model
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public TrackingCodeViewModel ConvertToView(TrackingCode code)
        {
            TrackingCodeViewModel model = new TrackingCodeViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(code.CustomerId);

            model.TrackingCodeId          = code.TrackingCodeId;
            model.CustomerId              = code.CustomerId;
            model.CustomerName            = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.TrackingCodeDescription = (!string.IsNullOrEmpty(code.Code)) ? code.Code : "N/A";
            model.IsActive = code.IsActive;

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

            return(model);
        }
Beispiel #10
0
        /// <summary>
        /// convert quote to list model
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public QuoteViewModel ConvertToListView(Quote quote)
        {
            QuoteViewModel model = new QuoteViewModel();

            var _rfqRepository = new RfqRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();

            var rfq = _rfqRepository.GetRfq(quote.RfqId);
            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(quote.CustomerId);

            model.QuoteId            = quote.QuoteId;
            model.QuoteNumber        = (!string.IsNullOrEmpty(quote.Number)) ? quote.Number : "N/A";
            model.QuoteDate          = quote.QuoteDate;
            model.QuoteDateStr       = quote.QuoteDate.ToShortDateString();
            model.CustomerName       = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.RfqNumber          = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A";
            model.IsOpen             = quote.IsOpen;
            model.IsHold             = quote.IsHold;
            model.IsCanceled         = quote.IsCanceled;
            model.Status             = quote.IsOpen ? "Open" : quote.IsCanceled ? "Canceled" : quote.IsHold ? "On Hold" : "N/A";
            model.CreatedDate        = quote.CreatedDate;
            model.HoldNotes          = quote.HoldNotes;
            model.HoldExpirationDate = quote.HoldExpirationDate;

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

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

            return(model);
        }
Beispiel #11
0
        /// <summary>
        /// convert memo to list model
        /// </summary>
        /// <param name="memo"></param>
        /// <returns></returns>
        public CreditMemoViewModel ConvertToListView(CreditMemo memo)
        {
            CreditMemoViewModel model = new CreditMemoViewModel();

            var _debitMemoRepository        = new DebitMemoRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();

            var debitMemo        = _debitMemoRepository.GetDebitMemo(memo.DebitMemoId);
            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(memo.CustomerId);

            model.CreditMemoId      = memo.CreditMemoId;
            model.CreditMemoNumber  = (!string.IsNullOrEmpty(memo.Number)) ? memo.Number : "N/A";
            model.CustomerId        = memo.CustomerId;
            model.FoundryId         = (debitMemo != null) ? debitMemo.FoundryId : string.Empty;
            model.CustomerName      = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.DebitMemoId       = memo.DebitMemoId;
            model.DebitMemoNumber   = (debitMemo != null && !string.IsNullOrEmpty(debitMemo.Number)) ? debitMemo.Number : "N/A";
            model.CreditMemoDate    = memo.CreditMemoDate;
            model.CreditMemoDateStr = memo.CreditMemoDate.ToShortDateString();
            model.CreditAmount      = memo.Amount;
            model.RmaNumber         = (debitMemo != null && !string.IsNullOrEmpty(debitMemo.RmaNumber)) ? debitMemo.RmaNumber : "N/A";

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

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

            return(model);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        /// <summary>
        /// convert packing list to view model
        /// </summary>
        /// <param name="packingList"></param>
        /// <returns></returns>
        public PackingListViewModel ConvertToView(PackingList packingList)
        {
            PackingListViewModel model = new PackingListViewModel();

            var _customerDynamicsRepository        = new CustomerDynamicsRepository();
            var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository();
            var _stateRepository       = new StateRepository();
            var _carrierRepository     = new CarrierRepository();
            var _packingListRepository = new PackingListRepository();

            var dynamicsCustomer        = _customerDynamicsRepository.GetCustomer(packingList.CustomerId);
            var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(packingList.CustomerAddressId);
            var state     = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty);
            var stateName = (state != null && !string.IsNullOrEmpty(state.Name)) ? ", " + state.Name : string.Empty;
            var carrier   = _carrierRepository.GetCarrier(packingList.CarrierId);

            model.PackingListId     = packingList.PackingListId;
            model.CustomerId        = packingList.CustomerId;
            model.CustomerName      = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CustomerAddressId = packingList.CustomerAddressId;
            model.CustomerAddress   = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " +
                                      dynamicsCustomerAddress.CITY + ", " + stateName : "N/A";
            model.ShipDate        = packingList.ShipDate;
            model.ShipDateStr     = packingList.ShipDate.ToShortDateString();
            model.Freight         = packingList.Freight;
            model.CarrierId       = packingList.CarrierId;
            model.CarrierName     = (carrier != null && !string.IsNullOrEmpty(carrier.Name)) ? carrier.Name : "N/A";
            model.TrailerNumber   = (!string.IsNullOrEmpty(packingList.TrailerNumber)) ? packingList.TrailerNumber : "N/A";
            model.TrackingNumber  = (!string.IsNullOrEmpty(packingList.TrackingNumber)) ? packingList.TrackingNumber : "N/A";
            model.Notes           = (!string.IsNullOrEmpty(packingList.Notes)) ? packingList.Notes : "N/A";
            model.NetWeight       = packingList.NetWeight;
            model.GrossWeight     = packingList.GrossWeight;
            model.DeliveryDate    = (packingList.DeliveryDate != null) ? packingList.DeliveryDate : DateTime.MinValue;;
            model.DeliveryDateStr = (packingList.DeliveryDate != null) ? packingList.DeliveryDate.Value.ToShortDateString() : "N/A";
            model.IsClosed        = packingList.IsClosed;
            model.ClosedDate      = (packingList.ClosedDate != null) ? packingList.ClosedDate : DateTime.MinValue;
            model.ClosedDateStr   = (packingList.ClosedDate != null) ? packingList.ClosedDate.Value.ToShortDateString() : "N/A";
            model.CreatedDate     = (packingList.CreatedDate != null) ? packingList.CreatedDate : DateTime.MinValue;
            model.CreatedDateStr  = (packingList.CreatedDate != null) ? packingList.CreatedDate.Value.ToShortDateString() : "N/A";

            var parts = _packingListRepository.GetPackingListPartsByPackingList(packingList.PackingListId);

            if (parts != null && parts.Count > 0)
            {
                var packingListParts = new List <PackingListPartViewModel>();

                foreach (var part in parts)
                {
                    PackingListPartViewModel packingListPart = new PackingListPartConverter().ConvertToView(part);
                    packingListParts.Add(packingListPart);
                }

                model.PackingListParts = packingListParts.OrderBy(x => x.ShipCode).ThenBy(y => y.PartNumber).ThenBy(z => z.PalletNumber).ToList();
            }

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

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

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

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

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

            return(model);
        }
Beispiel #14
0
        /// <summary>
        /// convert part to view model
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public PartViewModel ConvertToView(Part part)
        {
            PartViewModel model = new PartViewModel();

            var _partRepository             = new PartRepository();
            var _dynamicsPartRepository     = new PartDynamicsRepository();
            var _projectPartRepository      = new ProjectPartRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();
            var _htsNumberRepository        = new HtsNumberRepository();
            var _partTypeRepository         = new PartTypeRepository();
            var _partStatusRepository       = new PartStatusRepository();
            var _foundryOrderRepository     = new FoundryOrderRepository();

            var dynamicsPart             = _dynamicsPartRepository.GetPartMaster(part.Number);
            var dynamicsPartQty          = _dynamicsPartRepository.GetPartQuantityMaster(part.Number);
            var dynamicsPartCurrency     = _dynamicsPartRepository.GetPartCurrency(part.Number);
            var dynamicsPartRollingSales = _dynamicsPartRepository.GetItemRollingSales(part.Number);
            var foundryOrderPart         = _foundryOrderRepository.GetFoundryOrderPartByPart(part.PartId);

            if (foundryOrderPart != null)
            {
                var toolingOrder = _foundryOrderRepository.GetToolingFoundryOrder(foundryOrderPart.FoundryOrderId);
                model.FoundryOrderId     = (toolingOrder != null) ? foundryOrderPart.FoundryOrderId : Guid.Empty;
                model.ToolingOrderNumber = (toolingOrder != null && !string.IsNullOrEmpty(toolingOrder.Number)) ? toolingOrder.Number : "N/A";
                model.ToolingDescription = (!string.IsNullOrEmpty(part.ToolingDescription)) ? part.ToolingDescription : "N/A";
            }

            var latestDrawing = _partRepository.GetPartDrawings(part.PartId).FirstOrDefault(x => x.IsLatest == true);

            var weight = (dynamicsPart != null) ? Math.Round((dynamicsPart.ITEMSHWT / 100.00m), 2) : 0.00m;

            var yearlySalesTotal = (dynamicsPartRollingSales != null) ? (dynamicsPartRollingSales.Sales_1_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_2_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_3_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_4_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_5_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_6_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_7_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_8_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_9_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_10_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_11_mo_ago +
                                                                         dynamicsPartRollingSales.Sales_12_mo_ago) : 0.00m;

            model.ProjectPartId           = Guid.Empty;
            model.PartId                  = part.PartId;
            model.PartNumber              = (!string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A";
            model.AccountCode             = (!string.IsNullOrEmpty(part.AccountCode)) ? part.AccountCode : "N/A";
            model.PartDescription         = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A";
            model.RevisionNumber          = (latestDrawing != null && !string.IsNullOrEmpty(latestDrawing.RevisionNumber)) ? latestDrawing.RevisionNumber : "N/A";
            model.CustomerId              = part.CustomerId;
            model.CustomerAddressId       = part.CustomerAddressId;
            model.FoundryId               = part.FoundryId;
            model.SubFoundryId            = part.SubFoundryId;
            model.HtsNumberId             = part.HtsNumberId;
            model.MaterialId              = part.MaterialId;
            model.SpecificationMaterialId = part.MaterialSpecificationId;
            model.PartStatusId            = part.PartStatusId;
            model.PartTypeId              = part.PartTypeId;
            model.ShipmentTermId          = part.ShipmentTermId;
            model.PaymentTermId           = part.PaymentTermId;
            model.SurchargeId             = part.SurchargeId;
            model.SiteId                  = part.SiteId;
            model.DestinationId           = part.DestinationId;
            model.CoatingTypeId           = part.CoatingTypeId;
            model.PatternMaterialId       = part.PatternMaterialId;
            model.IsRaw               = part.IsRaw;
            model.IsMachined          = part.IsMachined;
            model.PalletQuantity      = (part.PalletQuantity != 0) ? part.PalletQuantity : 0;
            model.PalletWeight        = (part.PalletQuantity != 0) ? part.PalletQuantity * weight : 0.00m;
            model.Weight              = weight;
            model.Cost                = (dynamicsPart != null && (Math.Round(dynamicsPart.STNDCOST, 2) != 0.00m)) ? Math.Round(dynamicsPart.STNDCOST, 2) : 0.00m;
            model.Price               = (dynamicsPartCurrency != null && (Math.Round(dynamicsPartCurrency.LISTPRCE, 2) != 0.00m)) ? Math.Round(dynamicsPartCurrency.LISTPRCE, 2) : 0.00m;
            model.AdditionalCost      = (part.AdditionalCost != 0.00m) ? part.AdditionalCost : 0.00m;
            model.YearlySalesTotal    = Math.Round(yearlySalesTotal, 2);
            model.SixtyDaysSalesTotal = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 6), 2) : 0.00m;
            model.MonthlySalesTotal   = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 12), 2) : 0.00m;
            model.AverageDailySales   = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 365), 2) : 0.00m;
            model.QuantityOnHand      = (dynamicsPartQty != null && (Math.Round(dynamicsPartQty.QTYONHND, 2) != 0.00m)) ? Math.Round(dynamicsPartQty.QTYONHND, 2) : 0.00m;
            model.FixtureDate         = (part.FixtureDate != null) ? part.FixtureDate : DateTime.MinValue;
            model.FixtureDateStr      = (part.FixtureDate != null) ? part.FixtureDate.Value.ToShortDateString() : "N/A";
            model.FixtureCost         = (Math.Round(part.FixtureCost, 2) != 0.00m) ? Math.Round(part.FixtureCost, 2) : 0.00m;
            model.FixturePrice        = (Math.Round(part.FixturePrice, 2) != 0.00m) ? Math.Round(part.FixturePrice, 2) : 0.00m;
            model.PatternDate         = (part.PatternDate != null) ? part.PatternDate : DateTime.MinValue;
            model.PatternDateStr      = (part.PatternDate != null) ? part.PatternDate.Value.ToShortDateString() : "N/A";
            model.PatternCost         = (Math.Round(part.PatternCost, 2) != 0.00m) ? Math.Round(part.PatternCost, 2) : 0.00m;
            model.PatternPrice        = (Math.Round(part.PatternPrice, 2) != 0.00m) ? Math.Round(part.PatternPrice, 2) : 0.00m;
            model.IsFamilyPattern     = part.IsFamilyPattern;
            model.Notes               = (!string.IsNullOrEmpty(part.Notes)) ? part.Notes : "N/A";
            model.AnnualUsage         = (part.AnnualUsage != 0) ? part.AnnualUsage : 0;
            model.IsActive            = part.IsActive;
            model.IsProjectPart       = false;

            var partDrawings = _partRepository.GetPartDrawings(model.PartId ?? Guid.Empty);

            if (part.PartDrawings != null && part.PartDrawings.Count > 0)
            {
                var drawings = new List <DrawingViewModel>();

                foreach (var partDrawing in partDrawings)
                {
                    DrawingViewModel convertedModel = new PartDrawingConverter().ConvertToView(partDrawing);
                    drawings.Add(convertedModel);
                }

                model.Drawings = drawings;
            }

            var partLayouts = _partRepository.GetPartLayouts(model.PartId ?? Guid.Empty);

            if (part.PartLayouts != null && part.PartLayouts.Count > 0)
            {
                var layouts = new List <LayoutViewModel>();

                foreach (var partLayout in partLayouts)
                {
                    LayoutViewModel convertedModel = new PartLayoutConverter().ConvertToView(partLayout);
                    layouts.Add(convertedModel);
                }

                model.Layouts = layouts;
            }

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

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

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

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

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

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

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

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

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

            return(model);
        }
Beispiel #15
0
        /// <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);
        }
Beispiel #16
0
        /// <summary>
        /// convert part to project part list model
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public ProjectPartViewModel ConvertToListView(Part part)
        {
            ProjectPartViewModel model = new ProjectPartViewModel();

            var _dynamicsPartRepository     = new PartDynamicsRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();
            var _htsNumberRepository        = new HtsNumberRepository();
            var _partTypeRepository         = new PartTypeRepository();
            var _partStatusRepository       = new PartStatusRepository();

            var dynamicsPart     = _dynamicsPartRepository.GetPartMaster(part.Number);
            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(part.CustomerId);
            var dynamicsFoundry  = _foundryDynamicsRepository.GetFoundry(part.FoundryId);
            var htsNumber        = _htsNumberRepository.GetHtsNumber(part.HtsNumberId);
            var partType         = _partTypeRepository.GetPartType(part.PartTypeId);
            var partStatus       = _partStatusRepository.GetPartStatus(part.PartStatusId);

            model.PartId                = part.PartId;
            model.PartNumber            = (!string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A";
            model.PartDescription       = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A";
            model.CustomerId            = part.CustomerId;
            model.CustomerName          = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.FoundryId             = part.FoundryId;
            model.FoundryName           = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.HtsNumberId           = part.HtsNumberId;
            model.HtsNumber             = (htsNumber != null && !string.IsNullOrEmpty(htsNumber.Description)) ? htsNumber.Description + "(" + (htsNumber.DutyRate * 100).ToString() + "%)" : "N/A";
            model.PartTypeId            = part.PartTypeId;
            model.PartTypeDescription   = (partType != null && !string.IsNullOrEmpty(partType.Description)) ? partType.Description : "N/A";
            model.PartStatusId          = part.PartStatusId;
            model.PartStatusDescription = (partStatus != null && !string.IsNullOrEmpty(partStatus.Description)) ? partStatus.Description : "N/A";
            model.IsProject             = false;

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

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

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

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

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

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

            return(model);
        }
Beispiel #17
0
        /// <summary>
        /// convert project to view model
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public ProjectViewModel ConvertToView(Project project)
        {
            ProjectViewModel model = new ProjectViewModel();

            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();
            var _projectRepository          = new ProjectRepository();
            var _partRepository             = new PartRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(project.CustomerId);
            var dynamicsFoundry  = _foundryDynamicsRepository.GetFoundry(project.FoundryId);

            model.ProjectId            = project.ProjectId;
            model.ProjectName          = (!string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A";
            model.CustomerId           = project.CustomerId;
            model.CustomerName         = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CustomerContact      = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.CNTCPRSN)) ? dynamicsCustomer.CNTCPRSN : "N/A";
            model.CustomerContactPhone = FormattingManager.FormatPhone(dynamicsCustomer.PHONE1);
            model.FoundryId            = project.FoundryId;
            model.FoundryName          = (dynamicsFoundry != null) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.FoundryContact       = (dynamicsFoundry != null) ? dynamicsFoundry.VNDCNTCT : "N/A";
            model.FoundryContactPhone  = FormattingManager.FormatPhone((dynamicsFoundry != null) ? dynamicsFoundry.PHNUMBR1 : string.Empty);
            model.CreatedDate          = (project.CreatedDate != null) ? project.CreatedDate : DateTime.MinValue;
            model.CreatedDateStr       = (project.CreatedDate != null) ? project.CreatedDate.Value.ToShortDateString() : "N/A";
            model.CreatedBy            = project.CreatedBy;
            model.ModifiedDate         = (project.ModifiedDate != null) ? project.ModifiedDate : DateTime.MinValue;
            model.ModifiedDateStr      = (project.ModifiedDate != null) ? project.ModifiedDate.Value.ToShortDateString() : "N/A";
            model.ModifiedBy           = project.ModifiedBy;
            model.IsOpen                = project.IsOpen;
            model.IsHold                = project.IsHold;
            model.HoldExpirationDate    = (project.HoldExpirationDate != null) ? project.HoldExpirationDate : DateTime.MinValue;;
            model.HoldExpirationDateStr = (project.HoldExpirationDate != null) ? project.HoldExpirationDate.Value.ToShortDateString() : "N/A";
            model.HoldNotes             = (!string.IsNullOrEmpty(project.HoldNotes)) ? project.HoldNotes : "N/A";
            model.IsCanceled            = project.IsCanceled;
            model.CanceledDate          = (project.CanceledDate != null) ? project.CanceledDate : DateTime.MinValue;
            model.CanceledDateStr       = (project.CanceledDate != null) ? project.CanceledDate.Value.ToShortDateString() : "N/A";
            model.CancelNotes           = (!string.IsNullOrEmpty(project.CancelNotes)) ? project.CancelNotes : "N/A";
            model.IsComplete            = project.IsComplete;
            model.CompletedDate         = (project.CompletedDate != null) ? project.CompletedDate : DateTime.MinValue;
            model.CompletedDateStr      = (project.CompletedDate != null) ? project.CompletedDate.Value.ToShortDateString() : "N/A";
            model.Status                = project.IsOpen ? "Open" : project.IsCanceled ? "Canceled" : project.IsComplete ? "Completed" : project.IsHold ? "On Hold" : "N/A";
            model.Duration              = (project.CompletedDate != null) ? (project.CompletedDate - project.CreatedDate).Value.Days : 0;

            var notes = new List <ProjectNoteViewModel>();

            var tempNotes = _projectRepository.GetProjectNotes(project.ProjectId);

            if (tempNotes != null && tempNotes.Count > 0)
            {
                foreach (var tempNote in tempNotes)
                {
                    ProjectNoteViewModel convertedModel = new ProjectNoteConverter().ConvertToView(tempNote);

                    notes.Add(convertedModel);
                }
            }

            model.ProjectNotes = notes.OrderBy(y => y.CreatedDate).ToList();

            var parts = new List <ProjectPartViewModel>();

            var tempParts = _partRepository.GetParts().Where(x => x.Projects.Any(y => y.ProjectId == project.ProjectId)).ToList();

            if (project.Parts != null && project.Parts.Count > 0)
            {
                foreach (var part in project.Parts)
                {
                    ProjectPartViewModel convertedModel = new ProjectPartConverter().ConvertToListView(part);

                    if (parts.FirstOrDefault(x => x.PartNumber == convertedModel.PartNumber) == null)
                    {
                        parts.Add(convertedModel);
                    }
                }
            }

            if (project.ProjectParts != null && project.ProjectParts.Count > 0)
            {
                foreach (var tempPart in project.ProjectParts.Where(x => x.PartId == null))
                {
                    ProjectPartViewModel convertedModel = new ProjectPartConverter().ConvertToListView(tempPart);

                    if (parts.FirstOrDefault(x => x.PartNumber == convertedModel.PartNumber) == null)
                    {
                        parts.Add(convertedModel);
                    }
                }
            }

            model.Parts = parts.OrderBy(x => x.PartNumber).ToList();

            if (project.Rfqs != null && project.Rfqs.Count > 0)
            {
                model.RFQs = new List <RfqViewModel>();
                foreach (var rfq in project.Rfqs)
                {
                    var rfqModel = new RfqConverter().ConvertToListView(rfq);
                    model.RFQs.Add(rfqModel);
                }
            }

            if (project.PriceSheets != null && project.PriceSheets.Count > 0)
            {
                model.PriceSheets = new List <PriceSheetListModel>();

                decimal profitMargin = 0;

                foreach (var priceSheet in project.PriceSheets)
                {
                    var priceSheetModel = new PriceSheetConverter().ConvertToListView(priceSheet);

                    model.PriceSheets.Add(priceSheetModel);

                    profitMargin += priceSheetModel.ProjectMargin;
                }

                model.ProjectMargin = (profitMargin / project.PriceSheets.Count).ToString("#.##") + '%';
            }

            if (project.Quotes != null && project.Quotes.Count > 0)
            {
                model.Quotes = new List <QuoteViewModel>();
                foreach (var quote in project.Quotes)
                {
                    var quoteModel = new QuoteConverter().ConvertToListView(quote);
                    model.Quotes.Add(quoteModel);
                }
            }

            if (project.CustomerOrders != null && project.CustomerOrders.Count > 0)
            {
                model.CustomerOrders = new List <CustomerOrderViewModel>();
                foreach (var customerOrder in project.CustomerOrders)
                {
                    var customerOrderModel = new CustomerOrderConverter().ConvertToListView(customerOrder);

                    model.CustomerOrders.Add(customerOrderModel);
                }
            }

            if (project.FoundryOrders != null && project.FoundryOrders.Count > 0)
            {
                model.FoundryOrders = new List <FoundryOrderViewModel>();
                foreach (var foundryOrder in project.FoundryOrders)
                {
                    var foundryOrderModel = new FoundryOrderConverter().ConvertToListView(foundryOrder);

                    model.FoundryOrders.Add(foundryOrderModel);
                }
            }

            if (project.Shipments != null && project.Shipments.Count > 0)
            {
                model.Shipments = new List <ShipmentViewModel>();
                foreach (var shipment in project.Shipments)
                {
                    var shipmentModel = new ShipmentConverter().ConvertToView(shipment);

                    model.Shipments.Add(shipmentModel);
                }
            }

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

            return(model);
        }
Beispiel #18
0
        /// <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);
        }
Beispiel #19
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);
        }
Beispiel #20
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);
        }
Beispiel #21
0
        /// <summary>
        /// convert foundry order to view model
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public FoundryOrderViewModel ConvertToView(FoundryOrder order)
        {
            FoundryOrderViewModel model = new FoundryOrderViewModel();

            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 _billOfLadingRepository    = new BillOfLadingRepository();
            var _customerOrderRepository   = new CustomerOrderRepository();
            var _foundryOrderRepository    = new FoundryOrderRepository();

            var project                 = _projectRepository.GetProject(order.ProjectId);
            var dynamicsCustomer        = _customerDynamicsRepository.GetCustomer(order.CustomerId);
            var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(order.CustomerAddressId);
            var state           = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty);
            var stateName       = (state != null && !string.IsNullOrEmpty(state.Name)) ? ", " + state.Name : string.Empty;
            var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(order.FoundryId);
            var dynamicsSite    = _siteDynamicsRepository.GetSite((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.LOCNCODE)) ? dynamicsCustomerAddress.LOCNCODE : string.Empty);
            var orderTerm       = _orderTermRepository.GetOrderTerm(order.ShipmentTermsId);
            var billOfLading    = _billOfLadingRepository.GetBillOfLadings().FirstOrDefault(x => x.FoundryId.Replace(" ", string.Empty).ToLower() == order.FoundryId.Replace(" ", string.Empty).ToLower());
            var parts           = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.FoundryOrderId == order.FoundryOrderId).ToList();

            model.FoundryOrderId        = order.FoundryOrderId;
            model.BillOfLadingId        = (billOfLading != null) ? billOfLading.BillOfLadingId : Guid.Empty;
            model.OrderNumber           = (!string.IsNullOrEmpty(order.Number)) ? order.Number : "N/A";
            model.CustomerId            = order.CustomerId;
            model.CustomerName          = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.CustomerAddressId     = order.CustomerAddressId;
            model.CustomerAddress       = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " + dynamicsCustomerAddress.CITY + ", " + stateName : "N/A";
            model.ProjectId             = order.ProjectId;
            model.ProjectName           = (project != null) ? project.Name : "N/A";
            model.FoundryId             = order.FoundryId;
            model.FoundryName           = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.OrderNotes            = (!string.IsNullOrEmpty(order.Notes)) ? order.Notes : "N/A";
            model.ShipmentTermsId       = order.ShipmentTermsId;
            model.ShipmentTerms         = (orderTerm != null) ? orderTerm.Description : "N/A";
            model.OrderDate             = order.OrderDate;
            model.PODate                = (order.OrderDate != null) ? order.OrderDate : DateTime.MinValue;
            model.PODateStr             = (order.OrderDate != null) ? order.OrderDate.ToShortDateString() : "N/A";
            model.DueDate               = (order.DueDate != null) ? order.DueDate : DateTime.MinValue;
            model.DueDateStr            = (order.DueDate != null) ? order.DueDate.Value.ToShortDateString() : "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.EstArrivalDate        = (order.EstArrivalDate != null) ? order.EstArrivalDate : DateTime.MinValue;
            model.EstArrivalDateStr     = (order.EstArrivalDate != null) ? order.EstArrivalDate.Value.ToShortDateString() : "N/A";
            model.ShipVia               = (!string.IsNullOrEmpty(order.ShipVia)) ? order.ShipVia : "N/A";
            model.TransitDays           = order.TransitDays;
            model.SiteId                = order.SiteId;
            model.SiteDescription       = (dynamicsSite != null && !string.IsNullOrEmpty(dynamicsSite.LOCNDSCR)) ? dynamicsSite.LOCNDSCR : "N/A";
            model.IsOpen                = order.IsOpen ? true : false;
            model.IsConfirmed           = order.IsConfirmed;
            model.ConfirmedDate         = (order.ConfirmedDate != null) ? order.ConfirmedDate : DateTime.MinValue;
            model.ConfirmedDateStr      = (order.ConfirmedDate != null) ? order.ConfirmedDate.Value.ToShortDateString() : "N/A";
            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";

            if (parts != null && parts.Count > 0)
            {
                var foundryOrderParts = new List <FoundryOrderPartViewModel>();

                var totalPrice = 0.00m;

                foreach (var part in parts)
                {
                    FoundryOrderPartViewModel foundryOrderPart = new FoundryOrderPartViewModel();

                    if (model.OrderTypeDescription.Equals("Sample") || model.OrderTypeDescription.Equals("Tooling"))
                    {
                        foundryOrderPart = new FoundryOrderPartConverter().ConvertToProjectPartView(part);
                    }
                    else
                    {
                        foundryOrderPart = new FoundryOrderPartConverter().ConvertToPartView(part);
                    }

                    foundryOrderParts.Add(foundryOrderPart);

                    totalPrice += (foundryOrderPart.Price * foundryOrderPart.FoundryOrderQuantity);
                }

                model.TotalPrice        = Math.Round(totalPrice, 2);
                model.FoundryOrderParts = foundryOrderParts;
            }

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

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

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

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

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

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

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

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

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

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

            return(model);
        }
Beispiel #22
0
        /// <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);
        }
Beispiel #23
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);
        }