public async Task <IList <Project> > GetAllAsync() { using (CompanyDbContext context = CompanyDbContext.Create()) { var entities = await context.Project.ToListAsync(); return(entities.Select(ToDomain).ToList()); } }
public async Task <List <int> > GetAllProjectIdsByDeveloper(int developerId) { using (CompanyDbContext context = CompanyDbContext.Create()) { List <int> ids = await context.ProjectDeveloper.Where(item => item.DeveloperId == developerId).Select(item => item.ProjectId).ToListAsync(); return(ids); } }
public async Task <bool> InviteDeveloperToProject(int developerId, int projectId) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = new ProjectDeveloper { DeveloperId = developerId, ProjectId = projectId }; context.ProjectDeveloper.Add(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <Developer> CreateAsync(string firstName, string lastName, DateTime workedFrom) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = new Dal.Entitites.Developer { FirstName = firstName, LastName = lastName, WorkedFrom = workedFrom }; context.Developer.Add(entity); await context.SaveChangesAsync(); return(ToDomain(entity)); } }
public async Task <bool> DeleteDeveloperFromProject(int developerId, int projectId) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = await context.ProjectDeveloper.SingleOrDefaultAsync(item => item.DeveloperId == developerId && item.ProjectId == projectId); if (entity == null) { return(false); } context.ProjectDeveloper.Remove(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <bool> DeleteAsync(int id) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = await context.Project.SingleOrDefaultAsync(item => item.Id == id); if (entity == null) { return(false); } context.Project.Remove(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <Project> CreateAsync(string name, string description, DateTime startAt) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = new Dal.Entitites.Project { Description = description, Name = name, StartAt = startAt }; context.Project.Add(entity); await context.SaveChangesAsync(); return(ToDomain(entity)); } }
public async Task <Project> UpdatePropertiesAsync(int id, string name, string description, DateTime startAt) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = await context.Project.SingleOrDefaultAsync(item => item.Id == id); if (entity == null) { throw new InvalidOperationException($"Project with id='{id}' not found."); } entity.Name = name; entity.Description = description; entity.StartAt = startAt; await context.SaveChangesAsync(); return(ToDomain(entity)); } }
public async Task <Developer> UpdatePropertiesAsync(int id, string firstName, string lastName, DateTime workedFrom) { using (CompanyDbContext context = CompanyDbContext.Create()) { var entity = await context.Developer.SingleOrDefaultAsync(item => item.Id == id); if (entity == null) { throw new InvalidOperationException($"Developer with id='{id}' not found."); } entity.FirstName = firstName; entity.LastName = lastName; entity.WorkedFrom = workedFrom; await context.SaveChangesAsync(); return(ToDomain(entity)); } }