Esempio n. 1
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));
        }
Esempio 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);
        }