public IActionResult AddTask(int dayId, [FromBody] ToDoItemForCreationDto toDoItemForCreationDto) { if (toDoItemForCreationDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var taskMapped = _autoMapperWrapper.Map <ToDoItem>(toDoItemForCreationDto); _toDoListRepository.AddTask(dayId, taskMapped); if (!_toDoListRepository.SaveTask()) { return(StatusCode(500, "An error occurred while saving your task.")); } var taskToReturn = _autoMapperWrapper.Map <ToDoItemDto>(taskMapped); return(CreatedAtRoute("GetTaskById", new { dayId = dayId, id = taskToReturn.Id }, taskToReturn)); }
private void AddItem() { var task = new ToDo() { Id = Guid.NewGuid().ToString(), Task = view.Title, Description = view.Description }; repository.AddTask(task); }