コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }