示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
 public async Task <IEnumerable <Project> > GetProjectByNamesAsync(
     string[] names,
     [ScopedService] ProjectPortfolioDbContext context,
     CancellationToken cancellationToken) =>
 await context.Projects.Where(p => names.Contains(p.Name)).ToListAsync();
示例#5
0
 public Task <Project> GetProjectByNameAsync(
     string name,
     [ScopedService] ProjectPortfolioDbContext context,
     CancellationToken cancellationToken) =>
 context.Projects.FirstAsync(p => p.Name == name);
示例#6
0
 public IQueryable <Project> GetProjects(
     [ScopedService] ProjectPortfolioDbContext context) =>
 context.Projects.OrderBy(p => p.Name);
示例#7
0
 public ProjectController(ILogger <ProjectController> logger, ProjectPortfolioDbContext dbContext)
 {
     _logger    = logger;
     _dbContext = dbContext;
 }