public async Task <DeveloperViewModel> Handle(CreateDeveloperCommand request, CancellationToken cancellationToken) { var entity = new Developer( request.FullName, request.Commentary, request.Qualification ); await _context.Developers.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new DeveloperViewModel(entity)); }
public async Task <bool> Handle(DeleteDeveloperCommand request, CancellationToken cancellationToken) { var entity = await _context.Developers.FindAsync(request.Id); if (entity == null) { throw new InvalidRequestException(MainResource.ResourceNotExists); } _context.Developers.Remove(entity); await _context.SaveChangesAsync(cancellationToken); return(true); }
public async Task <bool> Handle(DeleteProjectMemberCommand request, CancellationToken cancellationToken) { var entity = await _context.ProjectMembers.FirstOrDefaultAsync(p => p.Id == request.ProjectMemberId && p.ProjectId == request.ProjectId, cancellationToken); if (entity == null) { throw new InvalidRequestException(MainResource.ResourceNotExists); } _context.ProjectMembers.Remove(entity); await _context.SaveChangesAsync(cancellationToken); return(true); }
public async Task <ProjectViewModel> Handle(CreateProjectCommand request, CancellationToken cancellationToken) { var entity = new Project( request.Name, request.StartDate, request.DeliveryDate, request.Description ); await _context.Projects.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(new ProjectViewModel(entity)); }
public async Task <ProjectMemberViewModel> Handle(AddMemberProjectCommand request, CancellationToken cancellationToken) { var entity = new ProjectMember( request.EntryDate, request.DeveloperId, request.ProjectId ); await _context.ProjectMembers.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); var persistedEntity = await _context.ProjectMembers .Include(c => c.Developer) .AsNoTracking() .SingleOrDefaultAsync(c => c.Id == entity.Id, cancellationToken: cancellationToken); return(new ProjectMemberViewModel(persistedEntity)); }
public async Task <DeveloperViewModel> Handle(UpdateDeveloperCommand request, CancellationToken cancellationToken) { var entity = await _context.Developers.FindAsync(request.Id); if (entity == null) { throw new InvalidRequestException(MainResource.ResourceNotExists); } entity.Commentary = request.Commentary; entity.FullName = request.FullName; entity.Qualification = request.Qualification; _context.Developers.Update(entity).State = EntityState.Modified; await _context.SaveChangesAsync(cancellationToken); return(new DeveloperViewModel(entity)); }
public async Task <ProjectViewModel> Handle(UpdateProjectCommand request, CancellationToken cancellationToken) { var entity = await _context.Projects.FindAsync(request.Id); if (entity == null) { throw new InvalidRequestException(MainResource.ResourceNotExists); } entity.Name = request.Name; entity.StartDate = request.StartDate; entity.DeliveryDate = request.DeliveryDate; entity.Description = request.Description; _context.Projects.Update(entity).State = EntityState.Modified; await _context.SaveChangesAsync(cancellationToken); return(new ProjectViewModel(entity)); }
public async Task <TimeEntryViewModel> Handle(CreateTimeEntryCommand request, CancellationToken cancellationToken) { var projectMember = await _context.ProjectMembers.SingleOrDefaultAsync(p => p.ProjectId == request.ProjectId && p.Id == request.ProjectMemberId, cancellationToken : cancellationToken); if (projectMember == null) { throw new InvalidRequestException(MainResource.ResourceNotExists); } var entity = new TimeEntry(request.Start, request.End, projectMember.Id); await _context.TimeEntries.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); var persistedEntity = await _context.TimeEntries .Include(c => c.ProjectMember) .ThenInclude(c => c.Developer) .AsNoTracking() .SingleOrDefaultAsync(c => c.Id == entity.Id, cancellationToken: cancellationToken); return(new TimeEntryViewModel(persistedEntity)); }