public IHttpActionResult PostTask(TaskViewModel viewModel) { if (ModelState.IsValid) { Task task = Mapper.Map <Task>(viewModel); _repository.AddTask(task); return(Created($"api/tasks/{viewModel.Title}", Mapper.Map <TaskViewModel>(viewModel))); } return(BadRequest("Failed to post task")); }
public async Task <IActionResult> AddTaskAsync(int userId, TaskInfo task, CancellationToken cancellationToken) { if (!ModelState.IsValid) { var errors = ModelState.StringifyModelErrors(); return(BadRequest(errors)); } var newTask = await _dataRepository.AddTask(userId, task); if (newTask == null) { _logger.LogDebug($"AddTaskAsync: failed to create task for user {userId}"); return(NotFound()); } return(Ok(task)); }
public ActionResult EditTask(TaskViewModel viewModel) { if (ModelState.IsValid) { Task task = Mapper.Map <Task>(viewModel); if (task.Id == 0) { _repository.AddTask(task); } else { _repository.EditTask(task); } return(RedirectToAction("Index")); } return(View(viewModel)); }