Esempio n. 1
0
        /// <summary>
        /// convert foundry order part to project part view model
        /// </summary>
        /// <param name="foundryOrderPart"></param>
        /// <returns></returns>
        public FoundryOrderPartViewModel ConvertToProjectPartView(FoundryOrderPart foundryOrderPart)
        {
            FoundryOrderPartViewModel model = new FoundryOrderPartViewModel();

            var _foundryOrderRepository    = new FoundryOrderRepository();
            var _customerOrderRepository   = new CustomerOrderRepository();
            var _projectPartRepository     = new ProjectPartRepository();
            var _dynamicsReceiptRepository = new ReceiptDynamicsRepository();

            var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId);
            var projectPart       = _projectPartRepository.GetProjectPart(foundryOrderPart.ProjectPartId);
            var customerOrder     = _customerOrderRepository.GetCustomerOrder((customerOrderPart != null) ? customerOrderPart.CustomerOrderId : Guid.Empty);

            model.FoundryOrderPartId   = foundryOrderPart.FoundryOrderPartId;
            model.CustomerOrderPartId  = foundryOrderPart.CustomerOrderPartId;
            model.FoundryOrderId       = foundryOrderPart.FoundryOrderId;
            model.ProjectPartId        = foundryOrderPart.ProjectPartId;
            model.CustomerOrderId      = (customerOrderPart != null) ? customerOrderPart.CustomerOrderId : Guid.Empty;
            model.AvailableQuantity    = (customerOrderPart != null) ? customerOrderPart.AvailableQuantity : 0;
            model.FoundryOrderQuantity = foundryOrderPart.Quantity;
            model.PartNumber           = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription      = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "N/A";
            model.PONumber             = (customerOrder != null && !string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A";
            model.ShipCode             = (!string.IsNullOrEmpty(foundryOrderPart.ShipCode)) ? foundryOrderPart.ShipCode : "N/A";
            model.ShipCodeNotes        = (!string.IsNullOrEmpty(foundryOrderPart.ShipCodeNotes)) ? foundryOrderPart.ShipCodeNotes : "N/A";
            model.EstArrivalDate       = (foundryOrderPart.EstArrivalDate != null) ? foundryOrderPart.EstArrivalDate : DateTime.MinValue;
            model.EstArrivalDateStr    = (foundryOrderPart.EstArrivalDate != null) ? foundryOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A";
            model.ShipDate             = (foundryOrderPart.ShipDate != null) ? foundryOrderPart.ShipDate : DateTime.MinValue;
            model.ShipDateStr          = (foundryOrderPart.ShipDate != null) ? foundryOrderPart.ShipDate.Value.ToShortDateString() : "N/A";
            model.Cost            = foundryOrderPart.Cost;
            model.Price           = foundryOrderPart.Price;
            model.IsScheduled     = foundryOrderPart.IsScheduled;
            model.HasBeenReceived = foundryOrderPart.HasBeenReceived;
            model.ReceiptDate     = (foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue;
            model.ReceiptDateStr  = (foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A";
            model.ReceiptQuantity = foundryOrderPart.ReceiptQuantity;

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

            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// convert foundry order part view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public FoundryOrderPart ConvertToDomain(FoundryOrderPartViewModel model)
        {
            FoundryOrderPart part = new FoundryOrderPart();

            var _customerOrderRepository = new CustomerOrderRepository();

            var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(model.CustomerOrderPartId);

            part.FoundryOrderPartId  = model.FoundryOrderPartId;
            part.ProjectPartId       = (customerOrderPart != null) ? customerOrderPart.ProjectPartId : null;
            part.PartId              = (customerOrderPart != null) ? customerOrderPart.PartId : null;
            part.CustomerOrderPartId = model.CustomerOrderPartId;
            part.AvailableQuantity   = model.AvailableQuantity;
            part.Quantity            = model.Quantity;
            part.EstArrivalDate      = model.EstArrivalDate;
            part.ShipDate            = model.ShipDate;
            part.ShipCode            = model.ShipCode;
            part.ShipCodeNotes       = model.ShipCodeNotes;
            part.Price           = model.Price;
            part.Cost            = model.Cost;
            part.IsScheduled     = model.IsScheduled;
            part.HasBeenReceived = model.HasBeenReceived;
            part.ReceiptDate     = model.ReceiptDate;
            part.ReceiptQuantity = model.ReceiptQuantity;

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

            return(part);
        }
Esempio n. 3
0
        /// <summary>
        /// convert customer order part to project part view model
        /// </summary>
        /// <param name="customerOrderPart"></param>
        /// <returns></returns>
        public CustomerOrderPartViewModel ConvertToProjectPartView(CustomerOrderPart customerOrderPart)
        {
            CustomerOrderPartViewModel model = new CustomerOrderPartViewModel();

            var _priceSheetRepository    = new PriceSheetRepository();
            var _projectPartRepository   = new ProjectPartRepository();
            var _customerOrderRepository = new CustomerOrderRepository();
            var _foundryOrderRepository  = new FoundryOrderRepository();

            var priceSheetPart   = _priceSheetRepository.GetPriceSheetPart(customerOrderPart.PriceSheetPartId);
            var projectPart      = _projectPartRepository.GetProjectPart((customerOrderPart.ProjectPartId != null) ? customerOrderPart.ProjectPartId : Guid.Empty);
            var priceSheet       = _priceSheetRepository.GetPriceSheet((priceSheetPart != null) ? priceSheetPart.PriceSheetId : Guid.Empty);
            var customerOrder    = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId);
            var receivedQuantity = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.CustomerOrderPartId == customerOrderPart.CustomerOrderPartId &&
                                                                                        x.HasBeenReceived).Select(y => y.ReceiptQuantity).Sum();

            model.CustomerOrderPartId   = customerOrderPart.CustomerOrderPartId;
            model.CustomerOrderId       = customerOrderPart.CustomerOrderId;
            model.PONumber              = (!string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A";
            model.ProjectPartId         = customerOrderPart.ProjectPartId;
            model.PriceSheetPartId      = customerOrderPart.PriceSheetPartId;
            model.PriceSheetId          = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty;
            model.AvailableQuantity     = customerOrderPart.AvailableQuantity;
            model.CustomerOrderQuantity = customerOrderPart.Quantity;
            model.PartNumber            = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription       = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "N/A";
            model.PriceSheetNumber      = (priceSheet != null && !string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A";
            model.EstArrivalDate        = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate : DateTime.MinValue;
            model.EstArrivalDateStr     = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A";
            model.ReceiptQuantity       = receivedQuantity;
            model.Cost  = customerOrderPart.Cost;
            model.Price = customerOrderPart.Price;

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

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

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

            return(model);
        }
Esempio n. 4
0
        /// <summary>
        /// convert container part to packlingList part view model
        /// </summary>
        /// <param name="containerPart"></param>
        /// <returns></returns>
        public PackingListPartViewModel ConvertToView(ContainerPart containerPart)
        {
            PackingListPartViewModel model = new PackingListPartViewModel();

            var _foundryOrderRepository  = new FoundryOrderRepository();
            var _partRepository          = new PartRepository();
            var _dynamicsPartRepository  = new PartDynamicsRepository();
            var _customerOrderRepository = new CustomerOrderRepository();

            var foundryOrderPart  = _foundryOrderRepository.GetFoundryOrderPart(containerPart.FoundryOrderPartId);
            var part              = _partRepository.GetPart(foundryOrderPart.PartId);
            var dynamicsPart      = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : null);
            var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId);
            var customerOrder     = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId);

            model.ShipCode       = foundryOrderPart.ShipCode;
            model.PartNumber     = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A";
            model.PartWeight     = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m;
            model.PartQuantity   = containerPart.Quantity;
            model.PalletNumber   = (!string.IsNullOrEmpty(containerPart.PalletNumber)) ? containerPart.PalletNumber : "N/A";
            model.PONumber       = (customerOrder != null && !string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A";
            model.PalletQuantity = containerPart.Quantity;
            model.InvoiceNumber  = "Will fill in later";

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

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

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

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

            return(model);
        }
Esempio n. 5
0
        /// <summary>
        /// convert packlingList part to view model
        /// </summary>
        /// <param name="packingListPart"></param>
        /// <returns></returns>
        public PackingListPartViewModel ConvertToView(PackingListPart packingListPart)
        {
            PackingListPartViewModel model = new PackingListPartViewModel();

            var _partRepository          = new PartRepository();
            var _customerOrderRepository = new CustomerOrderRepository();
            var _dynamicsPartRepository  = new PartDynamicsRepository();

            var part          = _partRepository.GetPart(packingListPart.PartNumber);
            var dynamicsPart  = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : null);
            var customerOrder = _customerOrderRepository.GetCustomerOrder(packingListPart.PONumber);

            model.PackingListPartId   = packingListPart.PackingListPartId;
            model.PackingListId       = packingListPart.PackingListId;
            model.PartId              = (part != null) ? part.PartId : Guid.Empty;
            model.ShipCode            = (!string.IsNullOrEmpty(packingListPart.ShipCode)) ? packingListPart.ShipCode : "N/A";
            model.PartNumber          = (!string.IsNullOrEmpty(packingListPart.PartNumber)) ? packingListPart.PartNumber : "N/A";
            model.PartWeight          = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m;
            model.PartQuantity        = packingListPart.PalletQuantity;
            model.PalletNumber        = (!string.IsNullOrEmpty(packingListPart.PalletNumber)) ? packingListPart.PalletNumber : "N/A";
            model.PalletQuantity      = packingListPart.PalletQuantity;
            model.PalletWeight        = packingListPart.PalletWeight;
            model.PalletTotal         = packingListPart.PalletTotal;
            model.TotalPalletQuantity = packingListPart.TotalPalletQuantity;
            model.PONumber            = (!string.IsNullOrEmpty(packingListPart.PONumber)) ? packingListPart.PONumber : "N/A";
            model.CustomerOrderId     = (customerOrder != null) ? customerOrder.CustomerOrderId : Guid.Empty;
            model.InvoiceNumber       = (!string.IsNullOrEmpty(packingListPart.InvoiceNumber)) ? packingListPart.InvoiceNumber : "N/A";

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

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

            return(model);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /// <summary>
        /// convert foundry order view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public FoundryOrder ConvertToDomain(FoundryOrderViewModel model)
        {
            var _customerOrderRepository = new CustomerOrderRepository();

            FoundryOrder order = new FoundryOrder();


            order.FoundryOrderId     = model.FoundryOrderId;
            order.Number             = model.OrderNumber;
            order.CustomerId         = model.CustomerId;
            order.ProjectId          = model.ProjectId;
            order.CustomerAddressId  = model.CustomerAddressId;
            order.FoundryId          = model.FoundryId;
            order.SiteId             = model.SiteId;
            order.ShipmentTermsId    = model.ShipmentTermsId;
            order.OrderDate          = model.OrderDate ?? DateTime.Now;
            order.ShipDate           = model.ShipDate;
            order.EstArrivalDate     = model.EstArrivalDate;
            order.DueDate            = model.DueDate;
            order.PortDate           = model.PortDate;
            order.Notes              = model.OrderNotes;
            order.ShipVia            = model.ShipVia;
            order.TransitDays        = model.TransitDays;
            order.IsConfirmed        = model.IsConfirmed;
            order.ConfirmedDate      = model.ConfirmedDate;
            order.IsOpen             = model.IsOpen;
            order.IsHold             = model.IsHold;
            order.HoldExpirationDate = (model.IsHold) ? model.HoldExpirationDate : null;
            order.HoldNotes          = (model.IsHold) ? model.HoldNotes : null;
            order.IsCanceled         = model.IsCanceled;
            order.CanceledDate       = (model.IsCanceled) ? model.CanceledDate : null;
            order.CancelNotes        = (model.IsCanceled) ? model.CancelNotes : null;
            order.IsComplete         = model.IsComplete;
            order.CompletedDate      = model.CompletedDate;
            order.IsSample           = model.IsSample;
            order.IsTooling          = model.IsTooling;
            order.IsProduction       = model.IsProduction;

            if (model.FoundryOrderParts != null && model.FoundryOrderParts.Count > 0)
            {
                var foundryOrderParts = new List <FoundryOrderPart>();

                foreach (var foundryOrderPart in model.FoundryOrderParts)
                {
                    var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId);

                    if (model.IsSample || model.IsTooling)
                    {
                        foundryOrderPart.ProjectPartId = (customerOrderPart != null) ? customerOrderPart.ProjectPartId : null;
                        foundryOrderPart.PartId        = null;
                    }
                    else
                    {
                        foundryOrderPart.ProjectPartId = null;
                        foundryOrderPart.PartId        = (customerOrderPart != null) ? customerOrderPart.PartId : null;
                    }

                    foundryOrderPart.FoundryOrderId = model.FoundryOrderId;

                    FoundryOrderPart orderPart = new FoundryOrderPartConverter().ConvertToDomain(foundryOrderPart);

                    foundryOrderParts.Add(orderPart);
                }

                order.FoundryOrderParts = foundryOrderParts;
            }

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

            return(order);
        }
Esempio n. 9
0
        /// <summary>
        /// convert container part to warehouse inventory list model
        /// </summary>
        /// <param name="containerPart"></param>
        /// <returns></returns>
        public WarehouseInventoryViewModel ConvertToListView(ContainerPart containerPart)
        {
            WarehouseInventoryViewModel model = new WarehouseInventoryViewModel();

            var _foundryOrderRepository  = new FoundryOrderRepository();
            var _customerOrderRepository = new CustomerOrderRepository();
            var _partRepository          = new PartRepository();
            var _dynamicsPartRepository  = new PartDynamicsRepository();
            var _containerRepository     = new ContainerRepository();

            var foundryOrderPart  = _foundryOrderRepository.GetFoundryOrderPart(containerPart.FoundryOrderPartId);
            var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart((foundryOrderPart != null) ? foundryOrderPart.CustomerOrderPartId : Guid.Empty);
            var part         = _partRepository.GetPart((foundryOrderPart != null) ? foundryOrderPart.PartId : Guid.Empty);
            var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : string.Empty);
            var container    = _containerRepository.GetContainer(containerPart.ContainerId);

            model.CustomerId       = (part != null) ? part.CustomerId : "N/A";
            model.ShipCode         = (foundryOrderPart != null) ? foundryOrderPart.ShipCode : "N/A";
            model.PartNumber       = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A";
            model.PartWeight       = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m;
            model.PalletNumber     = (!string.IsNullOrEmpty(part.Number)) ? containerPart.PalletNumber : "N/A";
            model.PalletQuantity   = containerPart.Quantity;
            model.TotalQuantity    = containerPart.Quantity;
            model.ContainerNumber  = (!string.IsNullOrEmpty(part.Number)) ? container.Number : "N/A";
            model.PONumber         = (customerOrderPart != null && !string.IsNullOrEmpty(customerOrderPart.CustomerOrder.PONumber)) ? customerOrderPart.CustomerOrder.PONumber : "N/A";
            model.WarehouseDate    = (foundryOrderPart != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue;
            model.WarehouseDateStr = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A";
            model.SixtyDaysDate    = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.AddDays(60) : DateTime.MinValue;
            model.SixtyDaysDateStr = (model.SixtyDaysDate != null) ? model.SixtyDaysDate.Value.ToShortDateString() : "N/A";

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

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

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

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

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

            return(model);
        }