Exemplo n.º 1
0
        public async Task <TimeTableDto> Handle(GetTimeTableQuery request, CancellationToken cancellationToken)
        {
            var timeTable = await _timeTableRepository.GetAsync(e =>
                                                                e.Id == request.Id);

            if (timeTable != null)
            {
                _logger.LogInformation($"Got a request get timeTable Id: {timeTable.Id}");
                var timeTableDto = _timeTableDxos.MapTimeTableDto(timeTable);
                return(timeTableDto);
            }

            return(null);
        }
Exemplo n.º 2
0
        public async Task <TimeTableDto> Handle(CreateTimeTableCommand request, CancellationToken cancellationToken)
        {
            var timeTableModel = _timeTableDxos.MapCreateRequesttoTimeTable(request);

            _timeTableRepository.Add(timeTableModel);

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

            await _mediator.Publish(new TimeTableCreatedEvent(timeTableModel.Id), cancellationToken);

            var timeTableDto = _timeTableDxos.MapTimeTableDto(timeTableModel);

            return(timeTableDto);
        }