/// <summary> /// Finds text input with identifier provided and returns its DTO /// </summary> /// <param name="performingUserId"></param> /// <param name="textInput"></param> /// <returns></returns> public ISelectionInputDto GetSelectionInput(int performingUserId, int textInputId) { using (var context = new PrometheusContext()) { return(ManualMapper.MapSelectionInputToDto(context.SelectionInputs.Find(textInputId))); } }
/// <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); }
/// <summary> /// Retrieve all. /// </summary> /// <returns></returns> public IEnumerable <ISelectionInputDto> GetSelectionInputs(int performingUserId) { using (var context = new PrometheusContext()) { var inputs = context.SelectionInputs; foreach (var input in inputs) { yield return(ManualMapper.MapSelectionInputToDto(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 ISelectionInputDto Create(int performingUserId, ISelectionInputDto entity) { using (var context = new PrometheusContext()) { var measure = context.SelectionInputs.Find(entity.Id); if (measure != null) { throw new InvalidOperationException(string.Format("Service Measure with ID {0} already exists.", entity.Id)); } var savedMeasure = context.SelectionInputs.Add(ManualMapper.MapDtoToSelectionInput(entity)); context.SaveChanges(performingUserId); return(ManualMapper.MapSelectionInputToDto(savedMeasure)); } }
/// <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 ISelectionInputDto Update(int performingUserId, ISelectionInputDto entity) { using (var context = new PrometheusContext()) { if (!context.SelectionInputs.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 updatedSelectionInput = ManualMapper.MapDtoToSelectionInput(entity); context.SelectionInputs.Attach(updatedSelectionInput); context.Entry(updatedSelectionInput).State = EntityState.Modified; context.SaveChanges(performingUserId); return(ManualMapper.MapSelectionInputToDto(updatedSelectionInput)); } }