/// <summary>
 /// Finds Scripted Selection Input with identifier provided and returns its DTO
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="scriptedSelection"></param>
 /// <returns></returns>
 public IScriptedSelectionInputDto GetScriptedSelectionInput(int performingUserId, int selectionInputId)
 {
     using (var context = new PrometheusContext())
     {
         return(ManualMapper.MapScriptedSelectionInputToDto(context.ScriptedSelectionInputs.Find(selectionInputId)));
     }
 }
 /// <summary>
 /// Returns a list of all of the Scripted Selection Inputs found
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <returns></returns>
 public IEnumerable <IScriptedSelectionInputDto> GetScriptedSelectionInputs(int performingUserId)
 {
     using (var context = new PrometheusContext())
     {
         var inputs = context.ScriptedSelectionInputs;
         foreach (var input in inputs)
         {
             yield return(ManualMapper.MapScriptedSelectionInputToDto(input));
         }
     }
 }
 /// <summary>
 /// Creates the entity in the database
 /// </summary>
 /// <param name="performingUserId">User creating the entity</param>
 /// <param name="entity">Entity to be created</param>
 /// <returns>Created entity DTO</returns>
 protected override IScriptedSelectionInputDto Create(int performingUserId, IScriptedSelectionInputDto entity)
 {
     using (var context = new PrometheusContext())
     {
         var input = context.ScriptedSelectionInputs.Find(entity.Id);
         if (input != null)
         {
             throw new InvalidOperationException(string.Format("Scripted Selection with ID {0} already exists.", entity.Id));
         }
         var saveInput = context.ScriptedSelectionInputs.Add(ManualMapper.MapDtoToScriptedSelectionInput(entity));
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapScriptedSelectionInputToDto(saveInput));
     }
 }
 /// <summary>
 /// Updates the entity in the database
 /// </summary>
 /// <param name="performingUserId">User updating the entity</param>
 /// <param name="entity">Entity to be updated</param>
 /// <returns>Updated entity DTO</returns>
 protected override IScriptedSelectionInputDto Update(int performingUserId, IScriptedSelectionInputDto entity)
 {
     using (var context = new PrometheusContext())
     {
         if (!context.ScriptedSelectionInputs.Any(x => x.Id == entity.Id))
         {
             throw new InvalidOperationException(
                       string.Format("Service Measure with ID {0} cannot be updated since it does not exist.", entity.Id));
         }
         var updatedScriptedSelection = ManualMapper.MapDtoToScriptedSelectionInput(entity);
         context.ScriptedSelectionInputs.Attach(updatedScriptedSelection);
         context.Entry(updatedScriptedSelection).State = EntityState.Modified;
         context.SaveChanges(performingUserId);
         return(ManualMapper.MapScriptedSelectionInputToDto(updatedScriptedSelection));
     }
 }
        /// <summary>
        /// Gets the required inputs for all supplied service options
        /// </summary>
        /// <param name="performingUserId"></param>
        /// <param name="serviceOptions">Service Options to get the inputs for</param>
        /// <returns></returns>
        public IInputGroupDto GetInputsForServiceOptions(int performingUserId, IEnumerable <IServiceOptionDto> serviceOptions)
        {
            if (serviceOptions == null)
            {
                base.ThrowArgumentNullError(nameof(serviceOptions));
            }

            var inputGroup = new InputGroupDto();

            //Initialize the lists for inputs
            List <IScriptedSelectionInputDto> scriptedInputs  = new List <IScriptedSelectionInputDto>();
            List <ISelectionInputDto>         selectionInputs = new List <ISelectionInputDto>();
            List <ITextInputDto> textInputs = new List <ITextInputDto>();

            using (var context = new PrometheusContext())
            {
                var options = serviceOptions.Select(x => context.ServiceOptions.Find(x.Id));
                foreach (var option in options)
                {
                    textInputs.AddRange(from t in option.TextInputs select ManualMapper.MapTextInputToDto(t));
                    scriptedInputs.AddRange(from t in option.ScriptedSelectionInputs select ManualMapper.MapScriptedSelectionInputToDto(t));
                    selectionInputs.AddRange(from t in option.SelectionInputs select ManualMapper.MapSelectionInputToDto(t));
                }
            }

            inputGroup.TextInputs              = textInputs;
            inputGroup.SelectionInputs         = selectionInputs;
            inputGroup.ScriptedSelectionInputs = scriptedInputs;
            return(inputGroup);
        }