Exemple #1
0
        /// <summary>
        /// convert bol to view model
        /// </summary>
        /// <param name="bol"></param>
        /// <returns></returns>
        public BillOfLadingViewModel ConvertToView(BillOfLading bol)
        {
            BillOfLadingViewModel model = new BillOfLadingViewModel();

            var _bolRepository             = new BillOfLadingRepository();
            var _foundryDynamicsRepository = new FoundryDynamicsRepository();
            var _foundryInvoiceRepository  = new FoundryInvoiceRepository();
            var _containerRepository       = new ContainerRepository();
            var _foundryOrderRepository    = new FoundryOrderRepository();

            var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(bol.FoundryId);
            var foundryInvoice  = _foundryInvoiceRepository.GetFoundryInvoiceByBillOfLading(bol.BillOfLadingId);
            var containers      = _containerRepository.GetContainers().Where(x => x.BillOfLadingId == bol.BillOfLadingId).ToList();

            model.BillOfLadingId       = bol.BillOfLadingId;
            model.ShipmentId           = bol.ShipmentId;
            model.FoundryId            = bol.FoundryId;
            model.BolNumber            = (!string.IsNullOrEmpty(bol.Number)) ? bol.Number : "N/A";
            model.BolDate              = bol.BolDate;
            model.BolDateStr           = (bol.BolDate != null) ? bol.BolDate.ToShortDateString() : "N/A";
            model.FoundryName          = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.Description          = (!string.IsNullOrEmpty(bol.Description)) ? bol.Description : "N/A";
            model.HasLcl               = bol.HasLcl;
            model.HasDoorMove          = bol.HasDoorMove;
            model.HasArrivalNotice     = bol.HasArrivalNotice;
            model.HasOriginalDocuments = bol.HasOriginalDocuments;
            model.PalletCount          = bol.PalletCount;
            model.GrossWeight          = bol.GrossWeight;
            model.NetWeight            = bol.NetWeight;
            model.BolNotes             = (!string.IsNullOrEmpty(bol.Notes)) ? bol.Notes : "N/A";
            model.WireInstructions     = (!string.IsNullOrEmpty(bol.WireInstructions)) ? bol.WireInstructions : "N/A";
            model.CustomsNumber        = (!string.IsNullOrEmpty(bol.CustomsNumber)) ? bol.CustomsNumber : "N/A";
            model.IsCustomsLiquidated  = bol.IsCustomsLiquidated;
            model.FoundryInvoiceId     = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty;
            model.BillOfLadingId       = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty;
            model.InvoiceNumber        = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A";
            model.InvoiceTotal         = (foundryInvoice != null) ? foundryInvoice.Amount : 0.00m;
            model.ScheduledDate        = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate : DateTime.MinValue;
            model.ScheduledDateStr     = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate.Value.ToShortDateString() : "N/A";
            model.ActualDate           = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate : DateTime.MinValue;
            model.ActualDateStr        = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate.Value.ToShortDateString() : "N/A";
            model.InvoiceNotes         = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Notes)) ? foundryInvoice.Notes : "N/A";
            model.HasBeenAnalyzed      = bol.HasBeenAnalyzed;

            if (containers != null && containers.Count > 0)
            {
                model.Containers = new List <ContainerViewModel>();

                foreach (var container in containers)
                {
                    ContainerViewModel convertedModel = new ContainerConverter().ConvertToView(container);

                    model.Containers.Add(convertedModel);
                }

                model.ContainerParts = new List <ContainerPartViewModel>();
                model.Pallets        = new List <PalletViewModel>();
                model.PurchaseOrders = new List <FoundryOrderViewModel>();

                foreach (var container in model.Containers)
                {
                    if (container.ContainerParts != null)
                    {
                        foreach (var containerPart in container.ContainerParts)
                        {
                            model.ContainerParts.Add(containerPart);
                            model.Pallets.Add(new PalletViewModel()
                            {
                                PalletNumber = containerPart.PalletNumber
                            });

                            var foundryOrder = _foundryOrderRepository.GetFoundryOrder(containerPart.FoundryOrderId);

                            if (foundryOrder != null)
                            {
                                FoundryOrderViewModel convertedModel = new FoundryOrderConverter().ConvertToView(foundryOrder);

                                model.PurchaseOrders.Add(convertedModel);
                            }
                        }
                    }
                }

                if (model.PurchaseOrders != null && model.PurchaseOrders.Count > 0)
                {
                    model.PurchaseOrders = model.PurchaseOrders.GroupBy(x => x.FoundryOrderId).Select(y => y.First()).ToList();
                }

                if (model.Pallets != null && model.Pallets.Count > 0)
                {
                    model.Pallets = model.Pallets.Distinct().ToList();
                }
            }

            model.FoundryInvoice = new FoundryInvoiceConverter().ConvertToView(foundryInvoice);

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

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

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

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

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

            return(model);
        }
Exemple #2
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);
        }