protected override async Task <IReadOnlyDictionary <Guid, Contract> > LoadBatchAsync( IReadOnlyList <Guid> keys, CancellationToken cancellationToken) { await using DogovorDbContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.Contracts .Where(s => keys.Contains(s.Id)) .ToDictionaryAsync(p => p.Id, cancellationToken)); }
public async Task <RenameContractPayload> RenameContractAsync( RenameContractInput input, [ScopedService] DogovorDbContext context, CancellationToken cancellationToken) { Contract contract = await context.Contracts.FindAsync(input.Id); contract.Name = input.Name; await context.SaveChangesAsync(cancellationToken); return(new RenameContractPayload(contract)); }
public async Task <AddContractPayload> AddContractAsync( AddContractInput input, [ScopedService] DogovorDbContext context, CancellationToken cancellationToken) { var contract = new Contract { Name = input.Name, CreatedDate = DateTime.Today }; context.Contracts.Add(contract); await context.SaveChangesAsync(cancellationToken); return(new AddContractPayload(contract)); }
public Task <Contract> GetContractByNameAsync( string name, [ScopedService] DogovorDbContext context, CancellationToken cancellationToken) { var project = new ProjectDto() { Name = "Project 1", Price = 45, Quantity = 99 }; var projectService = (IProjectService)_serviceProvider.GetService(typeof(IProjectService)); projectService.Put(project, cancellationToken); return(context.Contracts.FirstAsync(p => p.Name == name)); }
public async Task <IEnumerable <Contract> > GetContractByNamesAsync( string[] names, [ScopedService] DogovorDbContext context, CancellationToken cancellationToken) => await context.Contracts.Where(p => names.Contains(p.Name)).ToListAsync();
public IQueryable <Contract> GetContracts( [ScopedService] DogovorDbContext context) => context.Contracts.OrderBy(p => p.Name);