示例#1
0
        public async Task <ActivityDto> Handle(GetActivityQuery request, CancellationToken cancellationToken)
        {
            var activity = await _activityRepository.GetAsync(e =>
                                                              e.Id == request.Id);

            if (activity != null)
            {
                _logger.LogInformation($"Got a request get activity Id: {activity.Id}");
                var activityDto = _activityDxos.MapActivityDto(activity);
                return(activityDto);
            }

            return(null);
        }
        public async Task <ActivityDto> Handle(CreateActivityCommand request, CancellationToken cancellationToken)
        {
            var activityModel = _activityDxos.MapCreateRequesttoActivity(request);

            _activityRepository.Add(activityModel);

            if (await _activityRepository.SaveChangesAsync() == 0)
            {
                throw new ApplicationException("Insertion to database failed");
            }

            await _mediator.Publish(new ActivityCreatedEvent(activityModel.Id), cancellationToken);

            var activityDto = _activityDxos.MapActivityDto(activityModel);

            return(activityDto);
        }