Пример #1
0
        public async Task <int> Handle(SaveOperationRequestCommand request, CancellationToken cancellationToken)
        {
            var operationRequest = new AccountOperationRequest()
            {
                AccountId     = request.AccountId,
                CreationDate  = DateTime.UtcNow,
                Note          = request.Note,
                OperationType = request.Type,
                OperationDate = request.OperationDate,
                Amount        = request.Amount,
                Status        = AccountOperationStatus.Created,
            };

            operationRequest.Validate();

            if (!operationRequest.Valid)
            {
                _notificationContext.AddNotifications(operationRequest.ValidationResult);
                return(default(int));
            }

            _accountOperationRequestRepository.Add(operationRequest);

            await _unitOfWork.CommitAsync();

            operationRequest.JobReferenceId = _jobClient.Enqueue <IPerformOperationRequestJob>
                                                  (job => job.PerformOperation(operationRequest.Id),
                                                  request.OperationDate);

            _accountOperationRequestRepository.Update(operationRequest);

            await _unitOfWork.CommitAsync();

            return(operationRequest.Id);
        }
Пример #2
0
 public void Add()
 {
     //mediator.Publish(new Com.StarZ.MediatR.DemoNotification() { Message = DateTime.Now.ToString()});
     Console.WriteLine($"Add {DateTime.Now.ToString()}");
     jobClient.Enqueue(() => Console.WriteLine($"JOB {DateTime.Now.ToString()}"));
 }