예제 #1
0
        /// <summary>
        /// convert project part to part model for Create part
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public Part ConvertToCreatePart(ProjectPart projectPart)
        {
            Part part = new Part();

            var _projectPartRepository = new ProjectPartRepository();

            var projectPartDrawings = _projectPartRepository.GetProjectPartDrawings(projectPart.ProjectPartId);
            var projectPartLayouts  = _projectPartRepository.GetProjectPartLayouts(projectPart.ProjectPartId);

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

            if (projectPartDrawings != null && projectPartDrawings.Count > 0)
            {
                part.PartDrawings = new List <PartDrawing>();
                foreach (var projectPartDrawing in projectPartDrawings)
                {
                    var partDrawing = new PartDrawingConverter().ConvertToDomain(projectPartDrawing);
                    part.PartDrawings.Add(partDrawing);
                }
            }

            if (projectPartLayouts != null && projectPartLayouts.Count > 0)
            {
                part.PartLayouts = new List <PartLayout>();
                foreach (var projectPartLayout in projectPartLayouts)
                {
                    var partLayout = new PartLayoutConverter().ConvertToDomain(projectPartLayout);
                    part.PartLayouts.Add(partLayout);
                }
            }

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

            return(part);
        }
예제 #2
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);
        }