/// <summary> /// Handle /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommandResponse> Handle(CreateCommand command, CancellationToken cancellationToken) { CommandResponse response = new CommandResponse(); Core.Entities.ToDoItem entity = _mapper.Map <Core.Entities.ToDoItem>(command); await _repo.AddItemAsync(entity); response.Id = entity.Id; return(response); }
/// <summary> /// Handle /// </summary> /// <param name="query"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task<QueryResponse> Handle(GetQuery query, CancellationToken cancellationToken) { QueryResponse response = new QueryResponse(); Core.Entities.ToDoItem entity = await _repo.GetItemAsync(query.Id); if (entity == null) { throw new EntityNotFoundException(nameof(ToDoItem), query.Id); } response.Resource = _mapper.Map<ToDoItemModel>(entity); return response; }
/// <summary> /// Handle /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommandResponse> Handle(DeleteCommand command, CancellationToken cancellationToken) { CommandResponse response = new CommandResponse(); Core.Entities.ToDoItem entity = await _repo.GetItemAsync(command.Id); if (entity == null) { throw new EntityNotFoundException(nameof(ToDoItem), command.Id); } await _repo.DeleteItemAsync(command.Id); return(response); }
/// <summary> /// Handle /// </summary> /// <param name="command"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CommandResponse> Handle(UpdateCommand command, CancellationToken cancellationToken) { CommandResponse response = new CommandResponse(); Core.Entities.ToDoItem entity = await _repo.GetItemAsync(command.Id); if (entity == null) { throw new EntityNotFoundException(nameof(ToDoItem), command.Id); } entity.Category = command.Category; entity.Title = command.Title; await _repo.UpdateItemAsync(command.Id, entity); return(response); }
public async Task ToDo_Create_And_Update_Entry() { var toDoItem = new Core.Entities.ToDoItem { Title = "Test", CreatedOn = DateTime.Now, Status = Core.Enums.ToDoItemStatus.New }; var result = await _toDoRepository.AddAsync(toDoItem); result.Should().BeGreaterThan(0); toDoItem.Id = result; toDoItem.Title = "Changed for Update"; await _toDoRepository.UpdateAsync(toDoItem); var updatedToDoItem = await _toDoRepository.GetByIdAsync(result); updatedToDoItem.Should().NotBeNull(); updatedToDoItem.Title.Should().Be("Changed for Update"); }