/// <summary> /// Removes the supplied inputs from the ServiceOption provided /// </summary> /// <param name="performingUserId"></param> /// <param name="serviceOptionId">ID of Service Option to remove inputs from</param> /// <param name="inputsToRemove">Inputs to remove from the Service Option</param> /// <returns></returns> public IServiceOptionDto RemoveInputsFromServiceOption(int performingUserId, int serviceOptionId, IInputGroupDto inputsToRemove) { if (inputsToRemove == null) { base.ThrowArgumentNullError(nameof(inputsToRemove)); } using (var context = new PrometheusContext()) { var serviceOption = context.ServiceOptions.Find(serviceOptionId); if (serviceOption == null) { throw new EntityNotFoundException("Could not remove Inputs from Service Option.", typeof(ServiceOption), serviceOptionId); } foreach (var textInputToRemove in inputsToRemove.TextInputs) { if (serviceOption.TextInputs.Any(x => x.Id == textInputToRemove.Id)) { serviceOption.TextInputs.Remove(context.TextInputs.Find(textInputToRemove.Id)); } } foreach (var selectionInputToRemove in inputsToRemove.SelectionInputs) { if (serviceOption.SelectionInputs.Any(x => x.Id == selectionInputToRemove.Id)) { serviceOption.SelectionInputs.Remove(context.SelectionInputs.Find(selectionInputToRemove.Id)); } } foreach (var scriptedSelectionInputToRemove in inputsToRemove.ScriptedSelectionInputs) { if (serviceOption.ScriptedSelectionInputs.Any(x => x.Id == scriptedSelectionInputToRemove.Id)) { serviceOption.ScriptedSelectionInputs.Remove(context.ScriptedSelectionInputs.Find(scriptedSelectionInputToRemove.Id)); } } context.SaveChanges(performingUserId); return(ManualMapper.MapServiceOptionToDto(serviceOption)); } }
/// <summary> /// Adds the supplied inputs to the ServiceOption provided /// </summary> /// <param name="performingUserId"></param> /// <param name="serviceOptionId">ID of Service Option to add inputs to</param> /// <param name="inputsToAdd">Inputs to add to the Service Option</param> /// <returns></returns> public IServiceOptionDto AddInputsToServiceOption(int performingUserId, int serviceOptionId, IInputGroupDto inputsToAdd) { return(_serviceOptionController.AddInputsToServiceOption(performingUserId, serviceOptionId, inputsToAdd)); }
/// <summary> /// Removes the supplied inputs from the ServiceOption provided /// </summary> /// <param name="performingUserId"></param> /// <param name="serviceOptionId">ID of Service Option to remove inputs from</param> /// <param name="inputsToRemove">Inputs to remove from the Service Option</param> /// <returns></returns> public IServiceOptionDto RemoveInputsFromServiceOption(int performingUserId, int serviceOptionId, IInputGroupDto inputsToRemove) { return(_serviceOptionController.RemoveInputsFromServiceOption(performingUserId, serviceOptionId, inputsToRemove)); }
/// <summary> /// Get properly populated user inputs for an option /// </summary> /// <param name="id"></param> /// <param name="readOnly"></param> /// <returns></returns> public ActionResult GetOptionUserInputsDropDown(int id, bool readOnly = false) { List <SelectListItem> inputDropDownList = new List <SelectListItem>(); List <IUserInput> inputs = new List <IUserInput>(); var textInputs = _portfolioService.GetTextInputs(UserId); //store temporarily to check for nulls after var selectionInputs = _portfolioService.GetSelectionInputs(UserId); var scriptedInputs = _portfolioService.GetScriptedSelectionInputs(UserId); if (textInputs != null) { inputs.AddRange(from i in textInputs select(IUserInput) i); } if (selectionInputs != null) { inputs.AddRange(from i in selectionInputs select(IUserInput) i); } if (scriptedInputs != null) { inputs.AddRange(from i in scriptedInputs select(IUserInput) i); } inputs = inputs.OrderByDescending(i => i.DisplayName).ToList(); //sort all the data by display name //need to find already selected items //user inputs for this user input IInputGroupDto optionInputs = _portfolioService.GetInputsForServiceOptions(UserId, new List <IServiceOptionDto> { new ServiceOptionDto { Id = id } }); //now convert it to a select list for the drop down list foreach (var input in inputs) { var selected = false; //drop down list selection string type = null; if (input is TextInputDto) { type = "textInput"; if (optionInputs.TextInputs.Any() && (from i in optionInputs.TextInputs where i.Id == input.Id select true).FirstOrDefault()) { selected = true; } } else if (input is SelectionInputDto) { type = "selectionInput"; if (optionInputs.SelectionInputs.Any() && (from i in optionInputs.SelectionInputs where i.Id == input.Id select true).FirstOrDefault()) { selected = true; } } else if (input is ScriptedSelectionInputDto) { type = "scriptedSelectionInput"; if (optionInputs.ScriptedSelectionInputs.Any() && (from i in optionInputs.ScriptedSelectionInputs where i.Id == input.Id select true).FirstOrDefault()) { selected = true; } } inputDropDownList.Add(new SelectListItem { Value = $"{type}_{input.Id}", Text = input.DisplayName, Selected = selected }); } return(View("OptionUserInputsDropDown", inputDropDownList)); }