public async Task <TodoItemModel> CreateTodoItem(long listId, TodoItemCreateModel todoItem) { if (await _todoListRepository.GetById(listId) == null) { throw new KeyNotFoundException(); } if (await _todoItemRepository.ExistsByTitle(listId, todoItem.Title)) { throw new ModelValidationException("A todo with that title already exist in the list.", nameof(todoItem.Title)); } var entity = new Entities.Todo.TodoItem() { ListId = listId, Title = todoItem.Title, IsComplete = false }; entity.ListId = listId; _todoItemRepository.Insert(entity); await _todoUnitOfWork.SaveChanges(); return(_mapper.Map <TodoItemModel>(entity)); }
public async Task <IActionResult> Create(TodoItemCreateModel todoItem) { var item = ToTodoItem(todoItem); _services.AddAsync(item).Wait(); return(RedirectToAction("Index")); }
public async Task <IActionResult> CreateTodoItem(long listId, [FromBody] TodoItemCreateModel value) { var result = await _todoItemService.CreateTodoItem(listId, value); if (result != null) { return(CreatedAtAction(nameof(GetTodoItem), new { id = result.Id }, result)); } return(BadRequest()); }
private TodoItem ToTodoItem(TodoItemCreateModel model) { var todoItem = new TodoItem { Id = Guid.NewGuid(), Title = model.Title, IsCompleted = model.IsCompleted }; return(todoItem); }
public async Task <IActionResult> Create() { TodoItemCreateModel model = new TodoItemCreateModel(); return(View(model)); }