Пример #1
0
        /// <summary>
        /// convert part model to part master for update part master
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IV00101_Part_Master ConvertToUpdateMaster(PartOperationModel model)
        {
            IV00101_Part_Master partMaster = new IV00101_Part_Master();

            var _partStatusRepository = new PartStatusRepository();

            var partStatus = _partStatusRepository.GetPartStatus(model.PartStatusId);

            var active = (partStatus != null && (!partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("inactive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("archive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("purge"))) ? true : false;

            partMaster.ITEMNMBR = model.PartNumber;
            partMaster.ITEMDESC = model.PartDescription;
            partMaster.ITEMSHWT = Convert.ToInt32(model.Weight * 100.00m);
            partMaster.STNDCOST = model.Cost;
            partMaster.LOCNCODE = model.SiteId;
            partMaster.INACTIVE = Convert.ToByte(active);
            partMaster.ITMCLSCD = "STANDRRD";

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

            return(partMaster);
        }
Пример #2
0
        /// <summary>
        /// convert part model to domain for update part
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Part ConvertToUpdatePart(PartOperationModel model)
        {
            Part part = new Part();

            var _partStatusRepository = new PartStatusRepository();

            var partStatus = _partStatusRepository.GetPartStatus(model.PartStatusId);

            var active = (partStatus != null && (!partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("inactive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("archive") ||
                                                 !partStatus.Description.ToLower().Replace(" ", string.Empty).Equals("purge"))) ? true : false;

            part.PartId                  = model.PartId ?? Guid.Empty;
            part.Number                  = model.PartNumber;
            part.AccountCode             = model.AccountCode;
            part.CustomerId              = model.CustomerId;
            part.CustomerAddressId       = model.CustomerAddressId;
            part.FoundryId               = model.FoundryId;
            part.SubFoundryId            = model.SubFoundryId;
            part.HtsNumberId             = model.HtsNumberId;
            part.MaterialId              = model.MaterialId;
            part.MaterialSpecificationId = model.MaterialSpecificationId;
            part.PartStatusId            = model.PartStatusId;
            part.PartTypeId              = model.PartTypeId;
            part.ShipmentTermId          = model.ShipmentTermId;
            part.PaymentTermId           = model.PaymentTermId;
            part.SurchargeId             = model.SurchargeId;
            part.SiteId                  = model.SiteId;
            part.DestinationId           = model.DestinationId;
            part.CoatingTypeId           = model.CoatingTypeId;
            part.PatternMaterialId       = model.PatternMaterialId;
            part.IsRaw              = model.IsRaw;
            part.IsMachined         = model.IsMachined;
            part.PalletQuantity     = model.PalletQuantity;
            part.AdditionalCost     = model.AdditionalCost;
            part.FixtureDate        = model.FixtureDate;
            part.FixtureCost        = model.FixtureCost;
            part.FixturePrice       = model.FixturePrice;
            part.PatternDate        = model.PatternDate;
            part.PatternCost        = model.PatternCost;
            part.PatternPrice       = model.PatternPrice;
            part.IsFamilyPattern    = model.IsFamilyPattern;
            part.Notes              = model.Notes;
            part.MinimumQuantity    = model.MinimumQuantity;
            part.SafetyQuantity     = model.SafetyQuantity;
            part.OrderCycle         = model.OrderCycle;
            part.LeadTime           = model.LeadTime;
            part.AnnualUsage        = model.AnnualUsage;
            part.FoundryOrderId     = model.FoundryOrderId;
            part.ToolingDescription = model.ToolingDescription;
            part.IsActive           = active;

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

            return(part);
        }
Пример #3
0
        /// <summary>
        /// convert part to quote part view model
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public QuotePartViewModel ConvertToView(Part part)
        {
            QuotePartViewModel model = new QuotePartViewModel();

            var _partRepository         = new PartRepository();
            var _dynamicsPartRepository = new PartDynamicsRepository();
            var _partStatusRepository   = new PartStatusRepository();

            var dynamicsPart         = _dynamicsPartRepository.GetPartMaster(part.Number);
            var dynamicsPartCurrency = _dynamicsPartRepository.GetPartCurrency(part.Number);
            var partStatus           = _partStatusRepository.GetPartStatus(part.PartStatusId);
            var partDrawing          = _partRepository.GetPartDrawings(part.PartId).FirstOrDefault(x => x.IsLatest);

            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.FoundryId       = part.FoundryId;
            model.RevisionNumber  = (partDrawing != null && !string.IsNullOrEmpty(partDrawing.RevisionNumber)) ? partDrawing.RevisionNumber : "N/A";
            model.Weight          = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m;
            model.AnnualUsage     = part.AnnualUsage;
            model.Price           = (dynamicsPartCurrency != null) ? (decimal)dynamicsPartCurrency.LISTPRCE : 0.00m;
            model.PatternPrice    = part.PatternPrice;
            model.FixturePrice    = part.FixturePrice;
            model.Cost            = (dynamicsPart != null) ? (decimal)dynamicsPart.STNDCOST : 0.00m;
            model.PatternCost     = part.PatternCost;
            model.FixtureCost     = part.FixtureCost;
            model.IsRaw           = part.IsRaw;
            model.IsMachined      = part.IsMachined;

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

            return(model);
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        /// convert rfq part view model to project part
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ProjectPart ConvertToDomain(RfqPartViewModel model)
        {
            ProjectPart projectPart = new ProjectPart();

            var _partRepository        = new PartRepository();
            var _projectPartRepository = new ProjectPartRepository();
            var _partStatusRepository  = new PartStatusRepository();

            var active = _partStatusRepository.GetPartStates().FirstOrDefault(x => x.Description == "Active");

            projectPart.ProjectPartId     = model.ProjectPartId;
            projectPart.PartId            = model.PartId;
            projectPart.Number            = model.PartNumber;
            projectPart.AccountCode       = null;
            projectPart.Description       = model.PartDescription;
            projectPart.RevisionNumber    = model.RevisionNumber;
            projectPart.PriceSheetId      = null;
            projectPart.QuoteId           = null;
            projectPart.CustomerId        = model.CustomerId;
            projectPart.CustomerAddressId = null;
            projectPart.FoundryId         = model.FoundryId;
            projectPart.SubFoundryId      = (model.IsNew) ? model.FoundryId : model.SubFoundryId;
            projectPart.HtsNumberId       = null;
            projectPart.MaterialId        = model.MaterialId;
            projectPart.PartStatusId      = (model.IsNew) ? (active != null) ? active.PartStatusId : Guid.Empty : model.PartStatusId;
            projectPart.PartTypeId        = (model.IsNew) ? null : model.PartTypeId;
            projectPart.ShipmentTermId    = null;
            projectPart.PaymentTermId     = null;
            projectPart.SurchargeId       = (model.IsNew) ? null : model.SurchargeId;
            projectPart.SiteId            = null;
            projectPart.DestinationId     = (model.IsNew) ? null : model.DestinationId;
            projectPart.PatternMaterialId = null;
            projectPart.IsRaw             = model.IsRaw;
            projectPart.IsMachined        = model.IsMachined;
            projectPart.Weight            = model.Weight;
            projectPart.Cost               = 0.00m;
            projectPart.Price              = 0.00m;
            projectPart.PalletQuantity     = 0;
            projectPart.AdditionalCost     = 0.00m;
            projectPart.AnnualUsage        = model.AnnualUsage;
            projectPart.FixtureDate        = null;
            projectPart.FixtureCost        = 0.00m;
            projectPart.FixturePrice       = 0.00m;
            projectPart.PatternDate        = null;
            projectPart.PatternCost        = 0.00m;
            projectPart.PatternPrice       = 0.00m;
            projectPart.IsFamilyPattern    = false;
            projectPart.Notes              = null;
            projectPart.CustomerOrderId    = null;
            projectPart.FoundryOrderId     = null;
            projectPart.ToolingDescription = null;

            if (!string.IsNullOrEmpty(model.RevisionNumber) && model.RevisionNumber != "N/A")
            {
                projectPart.ProjectPartDrawings = new List <ProjectPartDrawing>();

                ProjectPartDrawing projectPartDrawing = new ProjectPartDrawing();

                if (model.Drawing != null)
                {
                    projectPartDrawing.ProjectPartId  = model.ProjectPartId;
                    projectPartDrawing.RevisionNumber = model.Drawing.RevisionNumber;
                    projectPartDrawing.Type           = model.Drawing.Type;
                    projectPartDrawing.Length         = model.Drawing.Length;
                    projectPartDrawing.Content        = model.Drawing.Content;
                    projectPartDrawing.IsLatest       = model.Drawing.IsLatest;
                    projectPartDrawing.IsMachined     = model.Drawing.IsMachined;
                    projectPartDrawing.IsRaw          = model.Drawing.IsRaw;
                    projectPartDrawing.IsActive       = model.Drawing.IsActive;
                }
                else
                {
                    if (model.PartId != null)
                    {
                        var drawing = _partRepository.GetPartDrawings(model.PartId ?? Guid.Empty).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber);
                        projectPartDrawing.ProjectPartId = model.ProjectPartId;
                        if (drawing != null)
                        {
                            projectPartDrawing.RevisionNumber = drawing.RevisionNumber;
                            projectPartDrawing.Type           = drawing.Type;
                            projectPartDrawing.Length         = drawing.Length;
                            projectPartDrawing.Content        = drawing.Content;
                            projectPartDrawing.IsLatest       = drawing.IsLatest;
                            projectPartDrawing.IsMachined     = drawing.IsMachined;
                            projectPartDrawing.IsRaw          = drawing.IsRaw;
                        }
                        projectPartDrawing.IsActive = true;
                    }
                    else
                    {
                        var drawing = _projectPartRepository.GetProjectPartDrawings(model.ProjectPartId).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber);
                        projectPartDrawing.ProjectPartId  = model.ProjectPartId;
                        projectPartDrawing.RevisionNumber = drawing.RevisionNumber;
                        projectPartDrawing.Type           = drawing.Type;
                        projectPartDrawing.Length         = drawing.Length;
                        projectPartDrawing.Content        = drawing.Content;
                        projectPartDrawing.IsLatest       = drawing.IsLatest;
                        projectPartDrawing.IsMachined     = drawing.IsMachined;
                        projectPartDrawing.IsRaw          = drawing.IsRaw;
                        projectPartDrawing.IsActive       = true;
                    }
                }

                projectPart.ProjectPartDrawings.Add(projectPartDrawing);
            }

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

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

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

            return(projectPart);
        }
Пример #6
0
        /// <summary>
        /// convert project part to part view model
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public PartViewModel ConvertToView(ProjectPart projectPart)
        {
            PartViewModel model = new PartViewModel();

            var _projectRepository      = new ProjectRepository();
            var _foundryOrderRepository = new FoundryOrderRepository();
            var _partTypeRepository     = new PartTypeRepository();
            var _partStatusRepository   = new PartStatusRepository();

            var partType         = _partTypeRepository.GetPartType(projectPart.PartTypeId);
            var statusEntity     = _partStatusRepository.GetPartStatus(projectPart.PartStatusId);
            var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderPartByProjectPart(projectPart.ProjectPartId);

            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 = projectPart.ToolingDescription;
            }

            model.ProjectPartId           = projectPart.ProjectPartId;
            model.PartId                  = projectPart.PartId;
            model.PartNumber              = (!string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription         = (!string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "N/A";
            model.AccountCode             = (!string.IsNullOrEmpty(projectPart.AccountCode)) ? projectPart.AccountCode : "N/A";
            model.RevisionNumber          = (!string.IsNullOrEmpty(projectPart.RevisionNumber)) ? projectPart.RevisionNumber : "N/A";
            model.CustomerId              = projectPart.CustomerId;
            model.CustomerAddressId       = projectPart.CustomerAddressId;
            model.FoundryId               = projectPart.FoundryId;
            model.SubFoundryId            = projectPart.SubFoundryId;
            model.HtsNumberId             = projectPart.HtsNumberId;
            model.MaterialId              = projectPart.MaterialId;
            model.SpecificationMaterialId = projectPart.MaterialSpecificationId;
            model.PartStatusId            = projectPart.PartStatusId;
            model.PartStatusDescription   = (statusEntity != null && !string.IsNullOrEmpty(statusEntity.Description)) ? statusEntity.Description : "N/A";
            model.PartTypeId              = projectPart.PartTypeId;
            model.PartTypeDescription     = (partType != null && !string.IsNullOrEmpty(partType.Description)) ? partType.Description : "N/A";
            model.ShipmentTermId          = projectPart.ShipmentTermId;
            model.PaymentTermId           = projectPart.PaymentTermId;
            model.SurchargeId             = projectPart.SurchargeId;
            model.SiteId                  = projectPart.SiteId;
            model.DestinationId           = projectPart.DestinationId;
            model.CoatingTypeId           = projectPart.CoatingTypeId;
            model.PatternMaterialId       = projectPart.PatternMaterialId;
            model.IsRaw               = projectPart.IsRaw;
            model.IsMachined          = projectPart.IsMachined;
            model.PalletQuantity      = (projectPart.PalletQuantity != 0) ? projectPart.PalletQuantity : 0;
            model.PalletWeight        = (projectPart.PalletQuantity != 0) ? projectPart.PalletQuantity * projectPart.Weight : 0.00m;
            model.Weight              = (projectPart.Weight != 0.00m) ? projectPart.Weight : 0.00m;
            model.Cost                = (projectPart.Cost != 0.00m) ? projectPart.Cost : 0.00m;
            model.Price               = (projectPart.Price != 0.00m) ? projectPart.Price : 0.00m;
            model.AdditionalCost      = (projectPart.AdditionalCost != 0.00m) ? projectPart.AdditionalCost : 0.00m;
            model.YearlySalesTotal    = 0.00m;
            model.SixtyDaysSalesTotal = 0.00m;
            model.MonthlySalesTotal   = 0.00m;
            model.AverageDailySales   = 0.00m;
            model.QuantityOnHand      = 0;
            model.FixtureDate         = (projectPart.FixtureDate != null) ? projectPart.FixtureDate : DateTime.MinValue;
            model.FixtureCost         = (projectPart.FixtureCost != 0.00m) ? projectPart.FixtureCost : 0.00m;
            model.FixturePrice        = (projectPart.FixturePrice != 0.00m) ? projectPart.FixturePrice : 0.00m;
            model.PatternDate         = projectPart.PatternDate;
            model.PatternCost         = (projectPart.PatternCost != 0.00m) ? projectPart.PatternCost : 0.00m;
            model.PatternPrice        = (projectPart.PatternPrice != 0.00m) ? projectPart.PatternPrice : 0.00m;
            model.IsFamilyPattern     = projectPart.IsFamilyPattern;
            model.Notes               = (projectPart.Notes != null) ? projectPart.Notes : "N/A";
            model.AnnualUsage         = (projectPart.PatternPrice != 0) ? projectPart.AnnualUsage : 0;
            model.IsActive            = true;
            model.IsProjectPart       = true;

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

                foreach (var partDrawing in projectPart.ProjectPartDrawings)
                {
                    DrawingViewModel convertedModel = new ProjectPartDrawingConverter().ConvertToView(partDrawing);
                    drawings.Add(convertedModel);
                }

                model.Drawings = drawings;
            }

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

                foreach (var partLayout in projectPart.ProjectPartLayouts)
                {
                    LayoutViewModel convertedModel = new ProjectPartLayoutConverter().ConvertToView(partLayout);
                    layouts.Add(convertedModel);
                }

                model.Layouts = layouts;
            }

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

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

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

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

            return(model);
        }
Пример #7
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);
        }