Пример #1
0
    public TryAsync <Employee> Execute(EmployeeUpdateCommand command, CancellationToken token) =>
    command
    .Apply(EmployeeRecord.Map.Merge)
    .Apply(record =>
    {
        string identifier = record.Id.ToString();

        return(client
               .GetEmployeesContainer()
               .ReplaceItemAsync(
                   record, identifier,
                   new PartitionKey(identifier),
                   new ItemRequestOptions {
            IfMatchEtag = record.ETag
        }, token));
    })
    .Apply(TryAsync)
    .Map(CosmosResponse.Unwrap)
    .SelectMany(record => QueueMessageBuilder
                .ToQueueMessage(queueClient, new EmployeeUpdate
    {
        EmployeeId = command.EntityToUpdate.Id
    })
                .Apply(TryAsync),
                (record, _) => record)
    .Map(EmployeeRecord.Map.ToEmployee);
 public TryAsync <Employee> Execute(EmployeeCreateCommand command, CancellationToken token) =>
 EmployeeRecord
 .Map
 .From(command.NewId, command.Employee)
 .Apply(record => client
        .GetEmployeesContainer()
        .CreateItemAsync(record, cancellationToken: token))
 .Apply(TryAsync)
 .Map(CosmosResponse.Unwrap)
 .SelectMany(record => QueueMessageBuilder
             .ToQueueMessage(queueClient, new EmployeeCreation
 {
     EmployeeId = command.NewId
 })
             .Apply(TryAsync),
             (record, _) => record)
 .Map(EmployeeRecord.Map.ToEmployee);
Пример #3
0
        public TryAsync <EmployeePayroll> Execute(EmployeePayrollCreateCommand command, CancellationToken token)
        {
            var(employee, newPayrollId, newEmployeePayroll) = command;

            return(EmployeePayrollRecord
                   .Map
                   .From(employee, newPayrollId, newEmployeePayroll)
                   .Apply(record => client.GetEmployeesContainer().CreateItemAsync(record, cancellationToken: token))
                   .Apply(TryAsync)
                   .Map(CosmosResponse.Unwrap)
                   .SelectMany(_ => QueueMessageBuilder
                               .ToQueueMessage(queueClient, new EmployeePayrollCreation
            {
                EmployeeId = employee.Id,
                EmployeePayrollId = newPayrollId,
            })
                               .Apply(TryAsync),
                               (record, _) => record)
                   .Map(EmployeePayrollRecord.Map.ToEmployeePayroll));
        }
Пример #4
0
 public TryAsync <EmployeePayroll> Execute(EmployeePayrollUpdateCommand command, CancellationToken token) =>
 command.Apply(EmployeePayrollRecord.Map.Merge)
 .Apply(record => client
        .GetEmployeesContainer()
        .ReplaceItemAsync(
            record, record.Id.ToString(),
            new PartitionKey(record.PartitionKey),
            new ItemRequestOptions {
     IfMatchEtag = record.ETag
 }, token))
 .Apply(TryAsync)
 .Map(CosmosResponse.Unwrap)
 .SelectMany(record => QueueMessageBuilder
             .ToQueueMessage(queueClient, new EmployeePayrollUpdate
 {
     EmployeeId        = command.EntityToUpdate.EmployeeId,
     EmployeePayrollId = command.EntityToUpdate.Id,
 })
             .Apply(TryAsync),
             (record, _) => record)
 .Map(EmployeePayrollRecord.Map.ToEmployeePayroll);