public async Task <ProjectTaskDTO> GetAsync(Guid id) { var entity = await _projectTaskRepository.GetByIdAsync(id); if (entity == null) { throw new Exception("Project task not found"); } return(entity.ToModel()); }
public async Task <Unit> Handle(UpdateTask request, CancellationToken cancellationToken) { var projectTask = await _projectTaskRepository.GetByIdAsync(request.Id, cancellationToken); if (projectTask == null) { throw new DomainException("Task does not exist!"); } if (projectTask.Title != request.Title && await _projectTaskRepository.Exists(request.Title, projectTask.ProjectId, cancellationToken)) { throw new DomainException($"Task with name {request.Title} exists!"); } projectTask.Title = request.Title; projectTask.Description = request.Description; projectTask.Type = request.Type; projectTask.ModifiedDate = DateTime.UtcNow; _logger.LogInformation("----- Updating Task - Task: {@Task}", projectTask); _projectTaskRepository.Update(projectTask); await _projectTaskRepository.UnitOfWork.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(DeleteTask request, CancellationToken cancellationToken) { var projectTask = await _projectTaskRepository.GetByIdAsync(request.Id, cancellationToken); if (projectTask != null) { _projectTaskRepository.Delete(projectTask); await _projectTaskRepository.UnitOfWork.SaveChangesAsync(cancellationToken); } return(Unit.Value); }