Beispiel #1
0
        public JsonResult Create(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);

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

            var project = _projectRepository.GetProject(model.ProjectName);

            if (project == null)
            {
                var newProject = new ProjectConverter().ConvertToCreate(model);

                operationResult = _projectRepository.SaveProject(newProject);

                model.ProjectId = operationResult.ReferenceId;
            }
            else
            {
                model.ProjectId = project.ProjectId;
            }

            var newRfq = new RfqConverter().ConvertToDomain(model);

            newRfq.ProjectId = model.ProjectId;

            operationResult = _rfqRepository.SaveRfq(newRfq);

            newRfq.RfqId = operationResult.ReferenceId;

            if (operationResult.Success && model != null)
            {
                foreach (var rfqPart in model.RfqParts)
                {
                    var newProjectPart = new ProjectPartConverter().ConvertToDomain(rfqPart);

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

                    operationResult = _projectPartRepository.SaveProjectPart(newProjectPart);
                }
            }

            operationResult.ReferenceId = newRfq.RfqId;

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult Create(QuoteViewModel model)
        {
            var operationResult = new OperationResult();

            Quote newQuote = new QuoteConverter().ConvertToDomain(model);

            operationResult = _quoteRepository.SaveQuote(newQuote);

            if (operationResult.Success)
            {
                var quoteId = operationResult.ReferenceId;

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

                if (rfq != null)
                {
                    rfq.IsOpen      = false;
                    operationResult = _rfqRepository.UpdateRfq(rfq);
                }

                var rfqId             = model.RfqId;
                var priceSheetId      = model.PriceSheetId;
                var projectId         = model.ProjectId;
                var customerAddressId = model.CustomerAddressId;
                var foundryId         = (rfq != null) ? rfq.FoundryId : string.Empty;
                var htsNumberId       = model.HtsNumberId;
                var shipmentTermId    = model.ShipmentTermId;
                var paymentTermId     = model.PaymentTermId;
                var materialId        = model.MaterialId;
                var coatingTypeId     = model.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.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);
                            }
                        }
                    }
                }

                operationResult.ReferenceId = quoteId;
            }



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