public void DeleteQuestion(DeleteQuestionRequest request) { AuthToken authToken = null; try { Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token"); Common.Helpers.ValidationHelper.ValidateRequiredField(request.AntiForgeryToken, "Auth Token"); if (!UserController.ValidateSession(request.AuthToken, out authToken)) { throw new AuthenticationException("Authentication failed."); } UserController.ValidateAntiForgeryToken(request.AntiForgeryToken, authToken); DbContext context = DataController.CreateDbContext(); Common.Helpers.ValidationHelper.AssertFalse(context.InterviewQuestions .Where(iq => iq.QuestionID == request.QuestionID) .Any(), "This question cannot be deleted as it has been used in existing interviews. Please delete those interviews first and then attempt to delete the question again."); E::Question question = context.Questions .Where(q => q.ID == request.QuestionID) .FirstOrDefault(); if (question.Tests.HasValue) { DataController.DeleteBlob(question.Tests.Value.ToString()); } context.Questions.Remove(question); context.SaveChanges(); } catch (AuthenticationException ex) { throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest); } catch (Common.Exceptions.ValidationException ex) { throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest); } catch (Exception ex) { ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username); throw new WebFaultException <string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError); } }
public async Task <IActionResult> DeleteQuestionAsync([FromRoute] DeleteQuestionRequest model, CancellationToken token) { try { var command = new DeleteQuestionCommand(model.Id, _userManager.GetLongUserId(User)); await _commandBus.DispatchAsync(command, token); return(Ok()); } catch (ArgumentException) { return(BadRequest()); } }
public async Task Delete([FromUri] DeleteQuestionRequest request) { await _mediator.ExecuteAsync(request).ConfigureAwait(false); }