示例#1
0
        public async Task <ReportResponse> Handle(CreateReportCommand request, CancellationToken cancellationToken)
        {
            var reportEntity = new ReportEntity
            {
                Id       = ObjectId.GenerateNewId().ToString(),
                Date     = DateTime.Now,
                Location = request.Location.ToString(),
                Status   = ReportStatusEnum.Preparing.ToString(),
            };

            await _reportRepository.CreateAsync(reportEntity);

            var response = await _reportRepository.GetAsync(reportEntity.Id);

            var model = new ReportResponse
            {
                Id          = response.Id,
                Date        = response.Date.ToString("dddd, dd MMMM yyyy"),
                Location    = response.Location,
                PersonCount = response.PersonCount,
                PhoneCount  = response.PhoneCount,
                Status      = response.Status
            };

            return(model);
        }
        public async Task <Unit> Handle(CreateReportCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Creating report '{reportType}' with parameters '{reportParameters}' requested by {userId}", message.ReportType, message.Parameters, message.RequestedBy.UserId);

            var now = _timeProvider.Now;

            var report = new Report(
                message.ReportId,
                message.Owner,
                ReportStatus.New,
                message.ReportName,
                message.ReportType,
                message.Parameters,
                message.RequestedBy,
                now);

            await _repository.CreateAsync(report);

            var queueMessage = new ReportQueueMessage
            {
                ReportId = report.Id
            };

            await _queue.AddMessageAsync(queueMessage);

            _logger.LogInformation("Finished create report '{reportType}' with parameters '{reportParameters}' requested by {userId}", message.ReportType, message.Parameters, message.RequestedBy.UserId);

            return(Unit.Value);
        }