public async Task <ActionResult <Todo> > AddTodo([FromBody] Todo todo) { try { Todo addedTodo = await service.AddTodoAsync(todo); return(Created($"/{addedTodo.TodoId}", addedTodo)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <ActionResult <Todo> > AddTodo([FromBody] Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Todo added = await todosService.AddTodoAsync(todo); return(Created($"/{added.TodoId}", added)); // return newly added to-do, to get the auto generated id } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }