Esempio 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);
        }
Esempio n. 2
0
        public async Task <DeleteResult> Handle(DeleteTimeTableCommand request, CancellationToken cancellationToken)
        {
            var timeTableModel = await _timeTableRepository.GetAsync(e => e.Id == request.Id);

            _timeTableRepository.Remove(timeTableModel);

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

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

            return(new DeleteResult(true));
        }