예제 #1
0
        /// <summary>Handles a request</summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Response from the request</returns>
        public async Task <Unit> Handle(PriceCalculateRequest request, CancellationToken cancellationToken)
        {
            // Some operations with entities
            // Update database with new rates
            // using UnitOfWork instance (_unitOfWork)

            // EXAMPLE:
            // ----------------------------------------------------------------------------
            // await _unitOfWork.SaveChangesAsync();
            // if (!_unitOfWork.LastSaveChangesResult.IsOk)
            // {
            //     await _workService.WorkFailedAsync(cancellationToken, request.WorkId, _unitOfWork.LastSaveChangesResult.Exception);
            //     return Unit.Value;

            //     // ---------------- OR --------------------------

            //     await _workService.RestartWorkAsync(request.WorkId, _unitOfWork.LastSaveChangesResult.Exception.Message);
            //     return Unit.Value;
            // }

            // Finishing the work
            await _workService.CompleteWorkAsync(cancellationToken, request.WorkId, "price generation completed");

            // and append new work for price generation
            await _worker.AppendWorkPriceGenerationAsync(cancellationToken);

            // return
            return(Unit.Value);
        }