public async Task <IActionResult> Delete([FromBody] DeleteQuestionViewModel model) { try { var response = await _service.DeleteQuestion(User, model, ModelState); return(response.JsonResult()); } catch (Exception error) { _logger.Error(error); return(StandardResponse.ForError().JsonResult()); } }
public async Task <IActionResult> DeleteQuestion(DeleteQuestionViewModel model) { if (ModelState.IsValid) { var question = await _evaluationManager.FindQuestionByIdAsync(model.Id); if (question == null) { return(NotFoundQuestion(model.Id)); } await _evaluationManager.DeleteQuestionAsync(question); Notifier.Success("你已成功删除了一条技术问题记录!"); return(RedirectToAction(nameof(Questions), new { model.EvaluationId, model.SubjectId })); } return(View(model)); }
public async Task <StandardResponse> DeleteQuestion(ClaimsPrincipal identity, DeleteQuestionViewModel model, ModelStateDictionary modelState) { if (!modelState.IsValid) { return(modelState.StandardError()); } using (var transaction = new ServiceDb().WithTransaction()) { using (var user = await _userService.Become(transaction.Db, identity, null)) { await _purgeService.PurgeExistingQuestion(transaction.Db, user, model.Id, new BackupConfig()); await transaction.Db.SaveChangesAsync(); return(StandardResponse.ForSuccess()); } } }