示例#1
0
        public JsonResult ValidateUpdate(Guid projectId)
        {
            var operationResult = new OperationResult();

            operationResult.Success = true;

            var projectParts = _projectPartRepository.GetProjectParts().Where(x => x.ProjectId == projectId).ToList();

            if (projectParts != null && projectParts.Count > 0)
            {
                foreach (var part in projectParts)
                {
                    var received = _foundryOrderRepository.GetFoundryOrderPartByProjectPart(part.ProjectPartId);

                    if (received != null)
                    {
                        operationResult.Success = false;
                        operationResult.Message = "Unable to put on hold or cancel, There are parts included in this project that have been received!";
                        break;
                    }
                }
            }

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public JsonResult Edit(RfqViewModel model)
        {
            var operationResult     = new OperationResult();
            var existingCoatingType = _coatingTypeRepository.GetCoatingType(model.CoatingType);

            if (existingCoatingType == null)
            {
                var newCoatingType = new CoatingType();
                {
                    newCoatingType.Description = model.CoatingType;
                    newCoatingType.IsActive    = true;
                }
                operationResult     = _coatingTypeRepository.SaveCoatingType(newCoatingType);
                existingCoatingType = _coatingTypeRepository.GetCoatingType(model.CoatingType);
            }

            var existingSpecificationMaterial = _specificationMaterialRepository.GetSpecificationMaterial(model.SpecificationMaterialDescription.ToLower().Replace(" ", string.Empty));

            if (existingSpecificationMaterial == null)
            {
                var newSpecificationMaterial = new SpecificationMaterial();
                {
                    newSpecificationMaterial.Description = model.SpecificationMaterialDescription;
                    newSpecificationMaterial.IsActive    = true;
                }
                operationResult = _specificationMaterialRepository.SaveSpecificationMaterial(newSpecificationMaterial);
                existingSpecificationMaterial = _specificationMaterialRepository.GetSpecificationMaterial(model.SpecificationMaterialDescription);
            }

            var rfqToUpdate = _rfqRepository.GetRfq(model.RfqId);

            rfqToUpdate = new RfqConverter().ConvertToDomain(model);

            var projectToUpdate = _projectRepository.GetProject(model.ProjectId);

            if (model.Status != null)
            {
                if (model.IsOpen)
                {
                    projectToUpdate.IsOpen = true;
                }
                else
                {
                    projectToUpdate.IsOpen = false;
                }

                if (model.IsHold)
                {
                    projectToUpdate.IsHold             = true;
                    projectToUpdate.HoldExpirationDate = model.HoldExpirationDate;
                    projectToUpdate.HoldNotes          = model.HoldNotes;
                }
                else
                {
                    projectToUpdate.IsHold             = false;
                    projectToUpdate.HoldExpirationDate = null;
                    projectToUpdate.HoldNotes          = null;
                }

                if (model.IsCanceled)
                {
                    projectToUpdate.IsCanceled  = true;
                    projectToUpdate.CancelNotes = model.CancelNotes;
                }
                else
                {
                    projectToUpdate.IsCanceled  = false;
                    projectToUpdate.CancelNotes = null;
                }
            }

            operationResult = _rfqRepository.UpdateRfq(rfqToUpdate);

            if (operationResult.Success)
            {
                model.Success    = true;
                model.IsHold     = rfqToUpdate.IsHold;
                model.IsCanceled = rfqToUpdate.IsCanceled;

                operationResult = _projectRepository.UpdateProject(projectToUpdate);

                if (model.RfqParts != null && model.RfqParts.Count() > 0)
                {
                    foreach (var rfqPart in model.RfqParts)
                    {
                        if (rfqPart.ProjectPartId != Guid.Empty)
                        {
                            var partToUpdate = new ProjectPartConverter().ConvertToDomain(rfqPart);
                            partToUpdate.RfqId     = model.RfqId;
                            partToUpdate.ProjectId = model.ProjectId;
                            partToUpdate.MaterialSpecificationId = existingSpecificationMaterial.SpecificationMaterialId;
                            partToUpdate.MaterialId    = rfqPart.MaterialId;
                            partToUpdate.CoatingTypeId = existingCoatingType.CoatingTypeId;
                            operationResult            = _projectPartRepository.UpdateProjectPart(partToUpdate);
                        }
                        else
                        {
                            var newProjectPart = new ProjectPartConverter().ConvertToDomain(rfqPart);

                            newProjectPart.RfqId      = model.RfqId;
                            newProjectPart.ProjectId  = model.ProjectId;
                            newProjectPart.MaterialId = rfqPart.MaterialId;
                            newProjectPart.MaterialSpecificationId = existingSpecificationMaterial.SpecificationMaterialId;
                            newProjectPart.CoatingTypeId           = existingCoatingType.CoatingTypeId;

                            operationResult = _projectPartRepository.SaveProjectPart(newProjectPart);
                        }
                    }
                }

                var existingProjectParts = _projectPartRepository.GetProjectParts().Where(x => x.ProjectId == model.ProjectId).ToList();

                if (existingProjectParts != null && existingProjectParts.Count > 0)
                {
                    foreach (var existingProjectPart in existingProjectParts)
                    {
                        var projectPart = model.RfqParts.FirstOrDefault(x => x.PartNumber == existingProjectPart.Number);

                        if (projectPart == null)
                        {
                            operationResult = _projectPartRepository.DeleteProjectPart(existingProjectPart.ProjectPartId);
                        }
                    }
                }

                if (!operationResult.Success)
                {
                    model.Success = false;
                    model.Message = operationResult.Message;
                }
            }
            else
            {
                model.Success = false;
                model.Message = operationResult.Message;
            }


            return(Json(model, JsonRequestBehavior.AllowGet));
        }
示例#3
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);
        }
示例#4
0
        public JsonResult Edit(QuoteViewModel model)
        {
            var operationResult = new OperationResult();

            var quoteToUpdate = new QuoteConverter().ConvertToDomain(model);

            operationResult = _quoteRepository.UpdateQuote(quoteToUpdate);

            if (operationResult.Success)
            {
                model.Success    = true;
                model.IsHold     = quoteToUpdate.IsHold;
                model.IsCanceled = quoteToUpdate.IsCanceled;

                var rfq               = _rfqRepository.GetRfq(quoteToUpdate.RfqId);
                var rfqId             = quoteToUpdate.RfqId;
                var priceSheetId      = quoteToUpdate.PriceSheetId;
                var quoteId           = model.QuoteId;
                var projectId         = quoteToUpdate.ProjectId;
                var customerAddressId = quoteToUpdate.CustomerAddressId;
                var foundryId         = (rfq != null) ? rfq.FoundryId : string.Empty;
                var htsNumberId       = model.HtsNumberId;
                var shipmentTermId    = model.ShipmentTermId;
                var paymentTermId     = model.PaymentTermId;
                var materialId        = quoteToUpdate.MaterialId;
                var coatingTypeId     = quoteToUpdate.CoatingTypeId;

                var quotePriceSheet = _priceSheetRepository.GetPriceSheet(priceSheetId ?? Guid.Empty);

                if (model.QuoteParts != null && model.QuoteParts.Count() > 0)
                {
                    foreach (var quotePart in model.QuoteParts)
                    {
                        var projectPart = new ProjectPartConverter().ConvertToDomain(quotePart);

                        projectPart.RfqId                   = rfqId;
                        projectPart.PriceSheetId            = priceSheetId;
                        projectPart.QuoteId                 = quoteId;
                        projectPart.ProjectId               = projectId;
                        projectPart.CustomerAddressId       = customerAddressId;
                        projectPart.FoundryId               = (string.IsNullOrEmpty(foundryId)) ? foundryId : projectPart.FoundryId;
                        projectPart.HtsNumberId             = htsNumberId;
                        projectPart.ShipmentTermId          = shipmentTermId;
                        projectPart.PaymentTermId           = paymentTermId;
                        projectPart.MaterialId              = materialId;
                        projectPart.MaterialSpecificationId = materialId;
                        projectPart.CoatingTypeId           = coatingTypeId;
                        projectPart.FixtureDate             = (quotePriceSheet != null) ? quotePriceSheet.CreatedDate : null; //enter from price sheet
                        projectPart.PatternDate             = (quotePriceSheet != null) ? quotePriceSheet.CreatedDate : null; //enter from price sheet

                        var projectPartToUpdate = _projectPartRepository.GetProjectPart(projectPart.ProjectPartId);

                        if (projectPartToUpdate != null)
                        {
                            operationResult = _projectPartRepository.UpdateProjectPart(projectPart);
                        }
                        else
                        {
                            operationResult           = _projectPartRepository.SaveProjectPart(projectPart);
                            projectPart.ProjectPartId = operationResult.ReferenceId;

                            if (quotePriceSheet != null)
                            {
                                var newPriceSheetPart = new PriceSheetPartConverter().ConvertToDomain(projectPart);

                                newPriceSheetPart.IsQuote      = true;
                                newPriceSheetPart.IsProduction = false;
                                operationResult = _priceSheetRepository.SavePriceSheetPart(newPriceSheetPart);
                            }
                        }
                    }
                }

                var existingParts = _projectPartRepository.GetProjectParts().Where(x => x.QuoteId == quoteId).ToList();

                if (existingParts != null)
                {
                    foreach (var existingPart in existingParts)
                    {
                        var part = model.QuoteParts.FirstOrDefault(x => x.PartNumber == existingPart.Number);

                        if (part == null)
                        {
                            existingPart.QuoteId = null;
                            operationResult      = _projectPartRepository.UpdateProjectPart(existingPart);
                        }
                    }
                }

                if (!operationResult.Success)
                {
                    model.Success = false;
                    model.Message = operationResult.Message;
                }
            }
            else
            {
                model.Success = false;
                model.Message = operationResult.Message;
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }