public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item) { item.CreateTime = DateTimeOffset.Now; item.ModifyTime = DateTimeOffset.Now; await _todoItemRepository.AddAsync(item); return(CreatedAtAction(nameof(GetTodoItem), new { id = item.ID }, item)); }
private static async Task InitializeDatabaseAsync(ITodoItemRepository repository) { var sessionList = await repository.ListAsync(); if (!sessionList.Any()) { await repository.AddAsync(GetTestTodos()); } }
public async Task <ToDoItem> AddItemAsync(ToDoItem toDoItem) { toDoItem.CreateDate = DateTime.Now; await todoItemRepository.AddAsync(toDoItem); await todoItemRepository.SaveAsync(); return(toDoItem); }
public async Task <IActionResult> Post([FromBody] TodoItem todo) { if (todo.UserId <= 0 || todo.CategoryId <= 0 || String.IsNullOrEmpty(todo.TodoTitle)) { return(new StatusCodeResult(StatusCodes.Status400BadRequest)); } await _todoItemRepository.AddAsync(todo); return(Json(todo)); }
public async Task <ActionResult> CreateItem([FromBody] TodoItem newTodoItem) { if (!ModelState.IsValid) { return(BadRequest()); } var toDo = await _repo.AddAsync(newTodoItem); return(Ok(toDo)); }
private async void AddItem(object todoItemValue) { TodoItem todoItem = todoItemValue as TodoItem; if (todoItem != null) { await repository.AddAsync(todoItem); TodoItems.Add(todoItem); } }
public async Task <CreateTodoItemResponseModel> CreateAsync(CreateTodoItemModel createTodoItemModel, CancellationToken cancellationToken = default) { var todoList = await _todoListRepository.GetFirstAsync(tl => tl.Id == createTodoItemModel.TodoListId); var todoItem = _mapper.Map <TodoItem>(createTodoItemModel); todoItem.List = todoList; return(new CreateTodoItemResponseModel { Id = (await _todoItemRepository.AddAsync(todoItem)).Id }); }
public async Task <CreateTodoItemResponseModel> CreateAsync(CreateTodoItemModel createTodoItemModel) { var todoList = await _todoListRepository.GetFirstAsync(tl => tl.Id == createTodoItemModel.TodoListId); var todoItem = _mapper.Map <TodoItem>(createTodoItemModel); todoItem.List = todoList ?? throw new NotFoundException("List does not exist anymore"); todoItem.IsDone = false; return(new CreateTodoItemResponseModel { Id = (await _todoItemRepository.AddAsync(todoItem)).Id }); }
public async Task HandleAsync(CreateTodo command, ICorrelationContext context) { if (await _repository.ExistsAsync(command.Id)) { //throw new MinotaurException("todo_item_already_exists", // $"Todo Item: '{command.Id}' already exists."); await _busPublisher.PublishAsync( new CreateTodoItemRejected(command.Id, "todo_item_already_exists", "Todo Item: already exists."), context); return; } var todoItem = new TodoItem(command.Id, command.UserId, command.Description, command.Title, command.IsDone); await _repository.AddAsync(todoItem); await _busPublisher.PublishAsync( new TodoItemCreated(command.Id, command.Title, command.Description, command.IsDone, command.UserId), context); }
public async Task <Either <TodoFailure, Unit> > Handle(AddTodoCommand request, CancellationToken cancellationToken) => await (from item in Validate(request) from _ in _todoItemRepository.AddAsync(item) select _).ToEither();