public async Task <ActionResult> Delete(int id) { try { string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1]; if (!await _repository.ValidateToken(token)) { return(Unauthorized()); } var taskModelFromRepository = await _repository.GetTaskById(id); if (taskModelFromRepository == null) { return(NotFound()); } int loggedUserId = Int32.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value); if (taskModelFromRepository.userId != loggedUserId) { return(Unauthorized()); } await _repository.DeleteTask(taskModelFromRepository); return(NoContent()); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public ActionResult DeleteTask(int id) { Task task = _repository.GetTaskById(id); _repository.DeleteTask(task); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteTaskAsync(TaskInfo task, CancellationToken cancellationToken) { if (!ModelState.IsValid) { var errors = ModelState.StringifyModelErrors(); return(BadRequest(errors)); } return(Ok(await _dataRepository.DeleteTask(task))); }
public IHttpActionResult DeleteTask(int id) { Task task = _repository.GetTaskById(id); if (task == null) { return(NotFound()); } _repository.DeleteTask(task); return(Ok(task)); }