/// <summary> /// Insert update the technical specifications /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public IResult ManageMaterialTechnicalSpecs(TechSpecsViewModel viewModel) { var result = new Result { Status = Status.Success }; try { if (string.IsNullOrEmpty(viewModel.TechSpecId) || viewModel.TechSpecId == null) { viewModel.TechSpecId = null; var technicalSpecification = new TechnicalSpecification(); technicalSpecification.MapFromViewModel(viewModel, (ClaimsIdentity)_principal.Identity); technicalSpecification.TechSpecId = ObjectId.GenerateNewId(); var updateDefinition = Builders <Material> .Update.Set(x => x.ModifiedDate, GenericHelper.CurrentDate).AddToSet(t => t.TechnicalSpecifications, technicalSpecification); _materialRepository.UpdateOne(t => t.MaterialId.Equals(ObjectId.Parse(viewModel.RegardingId)), updateDefinition); result.Body = technicalSpecification; result.Message = MaterialNotification.TechSpecCreated; result.Operation = Operation.Create; } else { var updateDefinition = Builders <Material> .Update.Set(x => x.ModifiedDate, GenericHelper.CurrentDate).Set(t => t.TechnicalSpecifications[-1].TechSpecName, viewModel.TechSpecName). Set(t => t.TechnicalSpecifications[-1].Value, viewModel.Value).Set(t => t.TechnicalSpecifications[-1].IncludeInOverview, viewModel.IncludeInOverview); _materialRepository.UpdateOne( t => t.MaterialId.Equals(ObjectId.Parse(viewModel.RegardingId)) && t.TechnicalSpecifications.Any(o => o.TechSpecId.Equals(ObjectId.Parse(viewModel.TechSpecId))), updateDefinition); result.Body = viewModel; result.Message = MaterialNotification.TechSpecUpdated; result.Operation = Operation.Update; } } catch (Exception e) { result.Message = e.Message; result.Status = Status.Fail; } return(result); }
public IResult ManageMaterialTechSpecs([FromBody] TechSpecsViewModel techSpecsViewModel) { var result = _materialManager.ManageMaterialTechnicalSpecs(techSpecsViewModel); return(result); }
public IResult ManageEquipmentTechSpecs([FromBody] TechSpecsViewModel techSpecsViewModel) { var result = _equipmentManager.ManageEquipmentTechnicalSpecs(techSpecsViewModel); return(result); }