public LanguageExt.TryOptionAsync <DepartmentPayroll> Execute(DepartmentPayrollQuery query, CancellationToken token)
        {
            var dataQuery = client.GetDepartmentsContainer()
                            .GetItemLinqQueryable <DepartmentPayrollRecord>(
                requestOptions: new QueryRequestOptions
            {
                PartitionKey = new PartitionKey(query.Department.ToLowerInvariant())
            })
                            .Where(e => e.EmployeePayrollId == query.EmployeePayrollId);

            return(async() =>
            {
                var iterator = dataQuery.ToFeedIterator();

                while (iterator.HasMoreResults)
                {
                    foreach (var result in await iterator.ReadNextAsync(token))
                    {
                        return DepartmentPayrollRecord.Map.ToDepartmentPayroll(result);
                    }
                }

                return None;
            });
        }
 public TryAsync <DepartmentPayroll> Execute(DepartmentPayrollCreateCommand command, CancellationToken token) =>
 DepartmentPayrollRecord
 .Map
 .CreateNewFrom(command.Employee, command.RecordId, command.EmployeePayroll)
 .Apply(record => client
        .GetDepartmentsContainer()
        .CreateItemAsync(record, cancellationToken: token))
 .Apply(TryAsync)
 .Map(CosmosResponse.Unwrap)
 .Map(DepartmentPayrollRecord.Map.ToDepartmentPayroll);
Example #3
0
    public TryAsync <DepartmentEmployee> Execute(DepartmentEmployeeUpdateCommand command, CancellationToken token)
    {
        var departmentsContainer = client.GetDepartmentsContainer();

        return(DepartmentEmployeeRecord
               .Map
               .Merge(command.Employee, command.DepartmentEmployee)
               .Apply(record => departmentsContainer
                      .ReplaceItemAsync(
                          record, record.Id.ToString(),
                          new PartitionKey(record.PartitionKey),
                          new ItemRequestOptions {
            IfMatchEtag = record.ETag
        }, token)
                      .Apply(TryAsync)
                      )
               .Map(CosmosResponse.Unwrap)
               .SelectMany(record =>
                           departmentsContainer
                           .GetItemLinqQueryable <DepartmentPayrollRecord>(requestOptions: new QueryRequestOptions
        {
            PartitionKey = new PartitionKey(record.PartitionKey)
        })
                           .Where(p => p.Type == nameof(DepartmentPayrollRecord))
                           .Where(p => p.EmployeeId == command.Employee.Id)
                           .ToFeedIterator()
                           .Apply(TryAsync),
                           (record, iterator) => new { record, iterator }
                           )
               .MapAsync(async aggregate =>
        {
            var record = aggregate.record;
            var iterator = aggregate.iterator;

            while (iterator.HasMoreResults)
            {
                foreach (var result in await iterator.ReadNextAsync(token))
                {
                    var recordToUpdate = DepartmentPayrollRecord.Map.Merge(command.Employee, result);

                    await departmentsContainer.ReplaceItemAsync(
                        recordToUpdate,
                        recordToUpdate.Id.ToString(),
                        new PartitionKey(recordToUpdate.PartitionKey),
                        new ItemRequestOptions {
                        IfMatchEtag = recordToUpdate.ETag
                    },
                        token);
                }
            }

            return DepartmentEmployeeRecord.Map.ToDepartmentEmployee(record);
        }));
    }
Example #4
0
 public TryAsync <DepartmentPayroll> Execute(DepartmentPayrollUpdateCommand command, CancellationToken token) =>
 DepartmentPayrollRecord
 .Map
 .Merge(command.Employee, command.EmployeePayroll, command.DepartmentPayroll)
 .Apply(record => client
        .GetDepartmentsContainer()
        .ReplaceItemAsync(
            record, record.Id.ToString(),
            new PartitionKey(record.PartitionKey),
            new ItemRequestOptions {
     IfMatchEtag = record.ETag
 }, token))
 .Apply(TryAsync)
 .Map(CosmosResponse.Unwrap)
 .Map(DepartmentPayrollRecord.Map.ToDepartmentPayroll);
 public static IOrderedQueryable <TRecord> DepartmentQueryable <TRecord>(this CosmosClient client, string partitionKey) =>
 client.GetDepartmentsContainer().GetItemLinqQueryable <TRecord>(requestOptions: new QueryRequestOptions
 {
     PartitionKey = new PartitionKey(partitionKey.ToLowerInvariant())
 });
 public static IOrderedQueryable <TRecord> DepartmentQueryable <TRecord>(this CosmosClient client) =>
 client.GetDepartmentsContainer().GetItemLinqQueryable <TRecord>();