예제 #1
0
        private OperationResult EditPriceSheetParts(Guid priceSheetId)
        {
            var operationResult = new OperationResult();

            var projectParts = _projectPartRepository.GetProjectParts().Where(x => x.PriceSheetId == priceSheetId).ToList();

            if (projectParts != null && projectParts.Count > 0)
            {
                foreach (var projectPart in projectParts)
                {
                    var existingPart = _partRepository.GetPart(projectPart.PartId);

                    if (existingPart != null)
                    {
                        PartOperationModel convertedModel = new PartOperationConverter().ConvertFromProjectPart(projectPart);

                        Part part = new PartConverter().ConvertToUpdatePart(convertedModel);

                        operationResult = _partRepository.UpdatePart(part);

                        IV00101_Part_Master partMaster = new PartConverter().ConvertToUpdateMaster(convertedModel);

                        operationResult = _partDynamicsRepository.UpdatePartMaster(partMaster);

                        IV00105_Part_Currency partCurrency = new PartConverter().ConvertToUpdateCurrency(convertedModel);

                        operationResult = _partDynamicsRepository.UpdatePartCurrency(partCurrency);
                    }
                }
            }

            return(operationResult);
        }
예제 #2
0
        private OperationResult ConvertProjectPartsToParts(Guid priceSheetId)
        {
            var operationResult = new OperationResult();

            var projectParts = _projectPartRepository.GetProjectParts().Where(x => x.PriceSheetId == priceSheetId).ToList();

            if (projectParts != null && projectParts.Count > 0)
            {
                foreach (var projectPart in projectParts)
                {
                    var existingPart = _partRepository.GetPart(projectPart.PartId);

                    if (existingPart != null)
                    {
                        PartOperationModel convertedModel = new PartOperationConverter().ConvertFromProjectPart(projectPart);

                        Part part = new PartConverter().ConvertToUpdatePart(convertedModel);

                        operationResult = _partRepository.UpdatePart(part);

                        var existingProject = _projectRepository.GetProject(projectPart.ProjectId);

                        if (existingProject != null)
                        {
                            if (existingProject.Parts.FirstOrDefault(x => x.PartId == part.PartId) == null)
                            {
                                existingProject.Parts.Add(part);
                                operationResult = _projectRepository.UpdateProject(existingProject);
                            }
                        }

                        IV00101_Part_Master partMaster = new PartConverter().ConvertToUpdateMaster(convertedModel);

                        operationResult = _partDynamicsRepository.UpdatePartMaster(partMaster);

                        IV00105_Part_Currency partCurrency = new PartConverter().ConvertToUpdateCurrency(convertedModel);

                        operationResult = _partDynamicsRepository.UpdatePartCurrency(partCurrency);
                    }
                    else
                    {
                        var existingProject = _projectRepository.GetProject(projectPart.ProjectId);

                        if (existingProject != null)
                        {
                            Part part = new PartConverter().ConvertToCreatePart(projectPart);
                            existingProject.Parts.Add(part);
                            operationResult = _projectRepository.UpdateProject(existingProject);
                            existingPart    = existingProject.Parts.FirstOrDefault(x => x.Number == part.Number);
                        }

                        projectPart.PartId = existingPart.PartId;

                        operationResult = _projectPartRepository.UpdateProjectPart(projectPart);

                        IV00101_Part_Master partMaster = new PartConverter().ConvertToCreateMaster(projectPart);

                        operationResult = _partDynamicsRepository.SavePartMaster(partMaster);

                        IV00105_Part_Currency partCurrency = new PartConverter().ConvertToCreateCurrency(projectPart);

                        operationResult = _partDynamicsRepository.SavePartCurrency(partCurrency);

                        IV00107_Part_Price_Option partPriceOption = new PartConverter().ConvertToCreatePriceOption(projectPart);

                        operationResult = _partDynamicsRepository.SavePartPriceOption(partPriceOption);

                        IV00108_Part_Price partPrice = new PartConverter().ConvertToCreatePrice(projectPart);

                        operationResult = _partDynamicsRepository.SavePartPrice(partPrice);

                        IV00103_Part_Vendor_Master partVendor = new PartConverter().ConvertToCreateVendor(projectPart);

                        operationResult = _partDynamicsRepository.SavePartVendorMaster(partVendor);

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

                        if (projectPartDrawings != null && projectPartDrawings.Count > 0)
                        {
                            foreach (var projectPartDrawing in projectPartDrawings)
                            {
                                operationResult = _projectPartRepository.DeleteProjectPartDrawing(projectPartDrawing.ProjectPartDrawingId);
                            }
                        }

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

                        if (projectPartLayouts != null && projectPartLayouts.Count > 0)
                        {
                            foreach (var projectPartLayout in projectPartLayouts)
                            {
                                operationResult = _projectPartRepository.DeleteProjectPartLayout(projectPartLayout.ProjectPartLayoutId);
                            }
                        }
                    }
                }
            }

            return(operationResult);
        }