Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public JsonResult Create(PriceSheetViewModel priceSheet)
        {
            var operationResult = new OperationResult();

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

            var newPriceSheet = new PriceSheetConverter().ConvertToDomain(priceSheet);

            operationResult = _priceSheetRepository.SavePriceSheet(newPriceSheet);

            if (operationResult.Success && priceSheet.IsQuote)
            {
                rfq.IsOpen      = false;
                operationResult = _rfqRepository.UpdateRfq(rfq);
            }

            var insertedPriceSheet = _priceSheetRepository.GetPriceSheet(priceSheet.Number);

            if (operationResult.Success)
            {
                if (priceSheet.CostDetailList != null && priceSheet.CostDetailList.Count > 0)
                {
                    foreach (var costDetail in priceSheet.CostDetailList)
                    {
                        var priceDetail = priceSheet.PriceDetailList.FirstOrDefault(x => x.ProjectPartId == costDetail.ProjectPartId);

                        var tempPart = _projectPartRepository.GetProjectPart(costDetail.ProjectPartId);
                        {
                            tempPart.Weight       = costDetail.Weight;
                            tempPart.AnnualUsage  = (int)costDetail.AnnualUsage;
                            tempPart.Cost         = costDetail.Cost;
                            tempPart.PatternCost  = costDetail.PatternCost;
                            tempPart.FixtureCost  = costDetail.FixtureCost;
                            tempPart.PriceSheetId = insertedPriceSheet.PriceSheetId;
                            tempPart.Price        = priceDetail.Price;
                            tempPart.PatternPrice = priceDetail.PatternPrice;
                            tempPart.FixturePrice = priceDetail.FixturePrice;
                        }
                        operationResult = _projectPartRepository.UpdateProjectPart(tempPart);
                    }
                }

                if (operationResult.Success && priceSheet.IsQuote)
                {
                    operationResult = _rfqRepository.UpdatePriceSheet(rfq.RfqId, priceSheet.Number);
                }
                else if (priceSheet.IsProduction && operationResult.Success)
                {
                    if (priceSheet.QuoteId != Guid.Empty)
                    {
                        var quote = _quoteRepository.GetQuote(priceSheet.QuoteId);
                        quote.IsOpen    = false;
                        operationResult = _quoteRepository.UpdateQuote(quote);
                    }

                    ConvertProjectPartsToParts(insertedPriceSheet.PriceSheetId);
                }
            }

            operationResult.ReferenceId = insertedPriceSheet.PriceSheetId;

            return(Json(operationResult, JsonRequestBehavior.AllowGet));;
        }
Ejemplo n.º 3
0
        public JsonResult EditStatus(ProjectViewModel model)
        {
            var result = new OperationResult();

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

            model.CustomerId  = projectToUpdate.CustomerId;
            model.ProjectName = projectToUpdate.Name;
            model.FoundryId   = projectToUpdate.FoundryId;

            switch (model.Status)
            {
            case "Open":
                model.IsOpen             = true;
                model.IsHold             = false;
                model.HoldExpirationDate = null;
                model.HoldNotes          = null;
                model.IsCanceled         = false;
                model.CancelNotes        = null;
                model.CanceledDate       = null;
                model.IsComplete         = false;
                model.CompletedDate      = null;
                break;

            case "On Hold":
                model.IsOpen             = false;
                model.IsHold             = true;
                model.HoldExpirationDate = model.HoldExpirationDate;
                model.HoldNotes          = model.HoldNotes;
                model.IsCanceled         = false;
                model.CancelNotes        = null;
                model.CanceledDate       = null;
                model.IsComplete         = false;
                model.CompletedDate      = null;

                foreach (var rfq in projectToUpdate.Rfqs)
                {
                    rfq.IsOpen             = false;
                    rfq.IsCanceled         = false;
                    rfq.CancelNotes        = null;
                    rfq.CanceledDate       = null;
                    rfq.IsHold             = true;
                    rfq.HoldExpirationDate = model.HoldExpirationDate;
                    rfq.HoldNotes          = model.HoldNotes;
                    _rfqRepository.UpdateRfq(rfq);
                }
                foreach (var quote in projectToUpdate.Quotes)
                {
                    quote.IsOpen             = false;
                    quote.IsCanceled         = false;
                    quote.CancelNotes        = null;
                    quote.CanceledDate       = null;
                    quote.IsHold             = true;
                    quote.HoldExpirationDate = model.HoldExpirationDate;
                    quote.HoldNotes          = model.HoldNotes;
                    _quoteRepository.UpdateQuote(quote);
                }
                foreach (var customerOrder in projectToUpdate.CustomerOrders)
                {
                    customerOrder.IsOpen             = false;
                    customerOrder.IsCanceled         = false;
                    customerOrder.CancelNotes        = null;
                    customerOrder.CanceledDate       = null;
                    customerOrder.IsComplete         = false;
                    customerOrder.IsHold             = true;
                    customerOrder.HoldExpirationDate = model.HoldExpirationDate;
                    customerOrder.HoldNotes          = model.HoldNotes;
                    _customerOrderRepository.UpdateCustomerOrder(customerOrder);
                }
                foreach (var foundryOrder in projectToUpdate.FoundryOrders)
                {
                    foundryOrder.IsOpen             = false;
                    foundryOrder.IsCanceled         = false;
                    foundryOrder.CancelNotes        = null;
                    foundryOrder.CanceledDate       = null;
                    foundryOrder.IsComplete         = false;
                    foundryOrder.IsHold             = true;
                    foundryOrder.HoldExpirationDate = model.HoldExpirationDate;
                    foundryOrder.HoldNotes          = model.HoldNotes;
                    _foundryOrderRepository.UpdateFoundryOrder(foundryOrder);
                }
                break;

            case "Canceled":
                model.IsOpen             = false;
                model.IsHold             = false;
                model.HoldExpirationDate = null;
                model.HoldNotes          = null;
                model.IsCanceled         = true;
                model.CancelNotes        = model.CancelNotes;
                model.CanceledDate       = DateTime.Now;
                model.IsComplete         = false;
                model.CompletedDate      = null;

                foreach (var rfq in projectToUpdate.Rfqs)
                {
                    rfq.IsOpen             = false;
                    rfq.IsHold             = false;
                    rfq.HoldExpirationDate = null;
                    rfq.HoldNotes          = null;
                    rfq.IsCanceled         = true;
                    rfq.CancelNotes        = model.CancelNotes;
                    rfq.CanceledDate       = DateTime.Now;
                    _rfqRepository.UpdateRfq(rfq);
                }
                foreach (var quote in projectToUpdate.Quotes)
                {
                    quote.IsOpen             = false;
                    quote.IsHold             = false;
                    quote.HoldExpirationDate = null;
                    quote.HoldNotes          = null;
                    quote.IsCanceled         = true;
                    quote.CancelNotes        = model.CancelNotes;
                    quote.CanceledDate       = DateTime.Now;
                    _quoteRepository.UpdateQuote(quote);
                }
                foreach (var customerOrder in projectToUpdate.CustomerOrders)
                {
                    customerOrder.IsOpen             = false;
                    customerOrder.IsHold             = false;
                    customerOrder.HoldExpirationDate = null;
                    customerOrder.HoldNotes          = null;
                    customerOrder.IsCanceled         = true;
                    customerOrder.CancelNotes        = model.CancelNotes;
                    customerOrder.CanceledDate       = DateTime.Now;
                    _customerOrderRepository.UpdateCustomerOrder(customerOrder);
                }
                foreach (var foundryOrder in projectToUpdate.FoundryOrders)
                {
                    foundryOrder.IsOpen             = false;
                    foundryOrder.IsHold             = false;
                    foundryOrder.HoldExpirationDate = null;
                    foundryOrder.HoldNotes          = null;
                    foundryOrder.IsCanceled         = true;
                    foundryOrder.CancelNotes        = model.CancelNotes;
                    foundryOrder.CanceledDate       = DateTime.Now;
                    _foundryOrderRepository.UpdateFoundryOrder(foundryOrder);
                }
                break;

            case "Complete":
                model.IsOpen             = false;
                model.IsHold             = false;
                model.HoldExpirationDate = null;
                model.HoldNotes          = null;
                model.IsCanceled         = true;
                model.CancelNotes        = null;
                model.CanceledDate       = null;
                model.IsComplete         = true;
                model.CompletedDate      = DateTime.Now;
                break;
            }

            Project project = new ProjectConverter().ConvertToUpdate(model);

            result = _projectRepository.UpdateProject(project);

            if (result.Success)
            {
                model.Success    = true;
                model.Status     = project.IsCanceled ? "Canceled" : project.IsComplete ? "Complete" : project.IsHold ? "On Hold" : "N/A";
                model.IsHold     = project.IsHold;
                model.IsCanceled = project.IsCanceled;
            }
            else
            {
                model.Success = false;
                model.Message = result.Message;
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
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));
        }