public async Task <Unit> Handle(UpdateRoomCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Rooms.FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Room), request.Id);
            }

            var before = entity.ToString();

            entity.RoomName = request.RoomName;

            var after = entity.ToString();

            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new CreateMailNotification
            {
                Subject = "Update calendar",
                Body    = $"Before:{Environment.NewLine}{Environment.NewLine}{before}" +
                          $"{Environment.NewLine}{Environment.NewLine}" +
                          $"After:{Environment.NewLine}{Environment.NewLine}{after}"
            });

            return(Unit.Value);
        }
        public async Task <int> Handle(CreateRoomCommand request, CancellationToken cancellationToken)
        {
            var entity = new Room
            {
                RoomName = request.Name,
            };

            _context.Rooms.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new CreateMailNotification { Subject = "Create room", Body = entity.ToString() });

            return(entity.RoomId);
        }
Пример #3
0
        public async Task <int> Handle(CreateCalendarCommand request, CancellationToken cancellationToken)
        {
            var entity = new Calendar
            {
                RoomId = request.RoomId,
                From   = request.From,
                To     = request.To
            };

            _context.Calendars.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new CreateMailNotification { Subject = "Create calendar", Body = entity.ToString() });

            return(entity.CalendarId);
        }
Пример #4
0
        public async Task <Unit> Handle(DeleteRoomCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Rooms.FindAsync(request.Id);

            if (entity == null)
            {
                throw new NotFoundException(nameof(Room), request.Id);
            }

            _context.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            await _mediator.Publish(new CreateMailNotification
            {
                Subject = "Delete room",
                Body    = $"Command remove that room:{Environment.NewLine}{entity.ToString()}"
            });

            return(Unit.Value);
        }