protected override async Task <IReadOnlyDictionary <Guid, Project> > LoadBatchAsync( IReadOnlyList <Guid> keys, CancellationToken cancellationToken) { await using ProjectPortfolioDbContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.Projects .Where(s => keys.Contains(s.Id)) .ToDictionaryAsync(p => p.Id, cancellationToken)); }
public async Task <RenameProjectPayload> RenameProjectAsync( RenameProjectInput input, [ScopedService] ProjectPortfolioDbContext context, CancellationToken cancellationToken) { Project project = await context.Projects.FindAsync(input.Id); project.Name = input.Name; await context.SaveChangesAsync(cancellationToken); return(new RenameProjectPayload(project)); }
public async Task <AddProjectPayload> AddProjectAsync( AddProjectInput input, [ScopedService] ProjectPortfolioDbContext context, CancellationToken cancellationToken) { var project = new Project { Name = input.Name, CreatedDate = DateTime.Today }; context.Projects.Add(project); await context.SaveChangesAsync(cancellationToken); return(new AddProjectPayload(project)); }
public async Task <IEnumerable <Project> > GetProjectByNamesAsync( string[] names, [ScopedService] ProjectPortfolioDbContext context, CancellationToken cancellationToken) => await context.Projects.Where(p => names.Contains(p.Name)).ToListAsync();
public Task <Project> GetProjectByNameAsync( string name, [ScopedService] ProjectPortfolioDbContext context, CancellationToken cancellationToken) => context.Projects.FirstAsync(p => p.Name == name);
public IQueryable <Project> GetProjects( [ScopedService] ProjectPortfolioDbContext context) => context.Projects.OrderBy(p => p.Name);
public ProjectController(ILogger <ProjectController> logger, ProjectPortfolioDbContext dbContext) { _logger = logger; _dbContext = dbContext; }