public JsonResult EditPart(PartOperationModel model) { var operationResult = new OperationResult(); if (model.IsProjectPart) { var currentPart = _projectPartRepository.GetProjectPart(model.ProjectPartId); if (currentPart != null) { currentPart = new ProjectPartConverter().ConvertToDomain(model); operationResult = _projectPartRepository.UpdateProjectPart(currentPart); if (operationResult.Success) { var partToEdit = _priceSheetRepository.GetProductionPriceSheetPartByProjectPart(currentPart.ProjectPartId); if (partToEdit != null) { partToEdit.Cost = model.Cost; partToEdit.Price = model.Price; partToEdit.AnnualCost = model.Cost * partToEdit.AnnualUsage; partToEdit.AnnualPrice = model.Price * partToEdit.AnnualUsage; operationResult = _priceSheetRepository.UpdatePriceSheetPart(partToEdit); var totalAnnualCost = _priceSheetRepository.GetPriceSheetParts(partToEdit.PriceSheetId).Select(x => x.AnnualCost).Sum(); var totalAnnualPrice = _priceSheetRepository.GetPriceSheetParts(partToEdit.PriceSheetId).Select(x => x.AnnualPrice).Sum(); var priceSheetToEdit = _priceSheetRepository.GetPriceSheet(partToEdit.PriceSheetId); priceSheetToEdit.AnnualMargin = (totalAnnualPrice - totalAnnualCost) / totalAnnualCost; operationResult = _priceSheetRepository.UpdatePriceSheet(priceSheetToEdit); } } } } else { var existingPart = _partRepository.GetPart(model.PartId); if (existingPart != null) { Part part = new PartConverter().ConvertToUpdatePart(model); operationResult = _partRepository.UpdatePart(part); } } return(Json(operationResult, JsonRequestBehavior.AllowGet)); }
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)); }
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)); }
public ActionResult Detail(Guid partId) { var model = new PartViewModel(); var currentPart = _projectPartRepository.GetProjectPart(partId); if (currentPart != null) { var projectPart = _projectPartRepository.GetProjectPart(partId); model = new ProjectPartConverter().ConvertToView(projectPart); } else { var part = _partRepository.GetPart(partId); model = new PartConverter().ConvertToView(part); } model.SelectableCustomers = _customerDynamicsRepository.GetSelectableCustomers(); var defaultCustomer = new SelectListItem() { Text = "--Select Customer--", Value = null }; model.SelectableCustomers.Insert(0, defaultCustomer); model.SelectableFoundries = _foundryDynamicsRepository.GetSelectableFoundries(); var defaultFoundry = new SelectListItem() { Text = "--Select Foundry--", Value = null }; model.SelectableFoundries.Insert(0, defaultFoundry); var htsNumbers = _htsNumberRepository.GetSelectableHtsNumbers(); var defaultHtsNumber = new SelectListItem() { Text = "--Select Hts Number--", Value = null }; htsNumbers.Insert(0, defaultHtsNumber); model.SelectableHtsNumbers = htsNumbers; var material = _materialRepository.GetSelectableMaterials(); var defaultMaterial = new SelectListItem() { Text = "--Select Material--", Value = null }; material.Insert(0, defaultMaterial); model.SelectableMaterial = material; var specificationMaterial = _specificationMaterialRepository.GetSelectableSpecificationMaterials(); var defaultSpecification = new SelectListItem() { Text = "--Select Material Specification--", Value = null }; specificationMaterial.Insert(0, defaultSpecification); model.SelectableSpecificationMaterial = specificationMaterial; var partStates = _partStatusRepository.GetSelectablePartStates(); var defaultPartStatus = new SelectListItem() { Text = "--Select Part Status--", Value = null }; partStates.Insert(0, defaultPartStatus); model.SelectablePartStates = partStates; var destinations = _destinationRepository.GetSelectableDestinations(); var defaultDestination = new SelectListItem() { Text = "--Select Destination--", Value = null }; destinations.Insert(0, defaultDestination); model.SelectableDestinations = destinations; var partTypes = _partTypeRepository.GetSelectablePartTypes(); var defaultPartType = new SelectListItem() { Text = "--Select Part Type--", Value = null }; partTypes.Insert(0, defaultPartType); model.SelectablePartTypes = partTypes; model.SelectableProjects = _projectRepository.GetSelectablePartProjects(partId); var paymentTerms = _paymentTermRepository.GetSelectablePaymentTerms(); var defaultPaymentTerm = new SelectListItem() { Text = "--Select Payment Term--", Value = null }; paymentTerms.Insert(0, defaultPaymentTerm); model.SelectablePaymentTerms = paymentTerms; var shipmentTerms = _shipmentTermRepository.GetSelectableShipmentTerms(); var defaultShipmentTerm = new SelectListItem() { Text = "--Select Shipment Term--", Value = null }; shipmentTerms.Insert(0, defaultShipmentTerm); model.SelectableShipmentTerms = shipmentTerms; var surcharge = _surchargeRepository.GetSelectableSurcharges(); model.SelectableSurcharge = surcharge; var defaultSurcharge = new SelectListItem() { Text = "--Select Surcharge--", Value = null }; surcharge.Insert(0, defaultSurcharge); model.SelectableSites = _siteDynamicsRepository.GetSelectableSites(); var defaultSite = new SelectListItem() { Text = "--Select Site--", Value = null }; model.SelectableSites.Insert(0, defaultSite); var coatingTypes = _coatingTypeRepository.GetSelectableCoatingTypes(); var defaultCoatingType = new SelectListItem() { Text = "--Select Coating Type--", Value = null }; coatingTypes.Insert(0, defaultCoatingType); model.SelectableCoatingTypes = coatingTypes; var patternMaterial = _patternMaterialRepository.GetSelectablePatternMaterials(); var defaultPattern = new SelectListItem() { Text = "--Select Pattern Material--", Value = null }; patternMaterial.Insert(0, defaultPattern); model.SelectablePatternMaterial = patternMaterial; return(View(model)); }
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)); }
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)); }