Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 public async Task <IEnumerable <Contract> > GetContractByNamesAsync(
     string[] names,
     [ScopedService] DogovorDbContext context,
     CancellationToken cancellationToken) =>
 await context.Contracts.Where(p => names.Contains(p.Name)).ToListAsync();
Beispiel #6
0
 public IQueryable <Contract> GetContracts(
     [ScopedService] DogovorDbContext context) =>
 context.Contracts.OrderBy(p => p.Name);