Esempio n. 1
0
        public JsonResult Delete(Guid rfqId)
        {
            var operationResult = new OperationResult();

            var existingRfq = _rfqRepository.GetRfq(rfqId);

            if (existingRfq != null)
            {
                var rfqCount = _rfqRepository.GetRfqs().Where(x => x.ProjectId == existingRfq.ProjectId).Count();

                if (rfqCount == 1)
                {
                    operationResult = _projectRepository.DeleteProject(existingRfq.ProjectId);
                }

                var projectParts = _projectPartRepository.GetProjectParts().Where(x => x.RfqId == rfqId).ToList();

                if (projectParts != null && projectParts.Count() > 0)
                {
                    foreach (var projectPart in projectParts)
                    {
                        var partDrawings = _projectPartRepository.GetProjectPartDrawings(projectPart.ProjectPartId);

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

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

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

                        operationResult = _projectPartRepository.DeleteProjectPart(projectPart.ProjectPartId);
                    }
                }

                operationResult = _rfqRepository.DeleteRfq(rfqId);
            }

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public JsonResult AddLayout(HttpPostedFileBase layout, Guid partId)
        {
            var operationResult = new OperationResult();

            var model = new LayoutPdf();

            if (layout != null && layout.ContentLength > 0)
            {
                byte[] tempFile = new byte[layout.ContentLength];
                layout.InputStream.Read(tempFile, 0, layout.ContentLength);

                var currentPart = _projectPartRepository.GetProjectPart(partId);

                if (currentPart != null)
                {
                    var newPartLayout = new ProjectPartLayoutConverter().ConvertToDomain(layout);

                    newPartLayout.ProjectPartId = partId;
                    newPartLayout.IsLatest      = true;
                    newPartLayout.IsMachined    = currentPart.IsMachined;
                    newPartLayout.IsRaw         = currentPart.IsRaw;

                    operationResult = _projectPartRepository.SaveProjectPartLayout(newPartLayout);

                    if (operationResult.Success)
                    {
                        var partLayouts = _projectPartRepository.GetProjectPartLayouts(partId);

                        foreach (var partLayout in partLayouts)
                        {
                            partLayout.IsLatest = false;
                            _projectPartRepository.UpdateProjectPartLayout(partLayout);
                        }

                        model.Success     = true;
                        model.LayoutId    = operationResult.ReferenceId;
                        model.Description = operationResult.Description;
                        model.IsProject   = true;
                    }
                    else
                    {
                        model.Success = false;
                        model.Message = operationResult.Message;
                    }
                }
                else
                {
                    var newPartLayout = new PartLayoutConverter().ConvertToDomain(layout);

                    newPartLayout.PartId     = partId;
                    newPartLayout.IsLatest   = true;
                    newPartLayout.IsMachined = false;
                    newPartLayout.IsRaw      = false;

                    operationResult = _partRepository.SavePartLayout(newPartLayout);

                    if (operationResult.Success)
                    {
                        var partLayouts = _partRepository.GetPartLayouts(partId);

                        foreach (var partLayout in partLayouts)
                        {
                            partLayout.IsLatest = false;
                            _partRepository.UpdatePartLayout(partLayout);
                        }

                        model.Success     = true;
                        model.LayoutId    = operationResult.ReferenceId;
                        model.Description = operationResult.Description;
                        model.IsProject   = true;
                    }
                    else
                    {
                        model.Success = false;
                        model.Message = operationResult.Message;
                    }
                }
            }

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