예제 #1
0
        //Start run
        public async Task <Unit> Handle(StartRunCommand request, CancellationToken cancellationToken)
        {
            var run = _mapper.Map <StartRunCommand, Run>(request);

            run.CreatedDate = _clock.UtcNow();

            await _runRepository.CreateAsync(run).ConfigureAwait(false);

            var evt = _mapper.Map <Run, RunStartedEvent>(run);

            await _eventPublisher.Publish(evt).ConfigureAwait(false);

            return(Unit.Value);
        }
예제 #2
0
        public async Task <ICommandResult> Start(string group = "tea")
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var roomItemGroup = await _mediator.Send(new GetRoomItemGroupByNameQuery(roomId : context.Room.Id, userId : context.User.Id, name : group)).ConfigureAwait(false);

            if (roomItemGroup == null)
            {
                return(Response(ErrorStrings.StartRun_GroupInvalidName(group), ResponseType.User));
            }

            if (!roomItemGroup.Options.Any())
            {
                return(Response(ErrorStrings.StartRun_GroupNoOptions(roomItemGroup.Name), ResponseType.User));
            }

            var command = new StartRunCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                userId: context.User.Id,
                roomId: context.Room.Id,
                roomGroupId: roomItemGroup.Id,
                startTime: _clock.UtcNow());

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(new SlashCommandResponse
            {
                Text = ResponseStrings.RunStarted(context.Command.UserId, roomItemGroup.Name),
                Type = ResponseType.Channel,
                Attachments = AttachmentBuilder.BuildOptions(roomItemGroup.Options)
            }));
        }
예제 #3
0
        public async Task <Unit> Handle(CreateOptionCommand request, CancellationToken cancellationToken)
        {
            var option = _mapper.Map <CreateOptionCommand, Option>(request);

            option.CreatedDate = _clock.UtcNow();

            await _optionsRepository.CreateAsync(option);

            return(Unit.Value);
        }
예제 #4
0
        public async Task <Unit> Handle(CreateRoomItemGroupCommand request, CancellationToken cancellationToken)
        {
            var roomGroup = _mapper.Map <CreateRoomItemGroupCommand, RoomItemGroup>(request);

            roomGroup.CreatedDate = _clock.UtcNow();

            await _optionsRepository.CreateGroupAsync(roomGroup);

            //todo: event

            return(Unit.Value);
        }
예제 #5
0
        public async Task <Unit> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var user = _mapper.Map <CreateUserCommand, User>(request);

            user.CreatedDate = _clock.UtcNow();

            await _userRepository.CreateAsync(user);

            //todo: create event

            return(Unit.Value);
        }
예제 #6
0
        public async Task <Unit> Handle(CreateRoomCommand request, CancellationToken cancellationToken)
        {
            var room = _mapper.Map <CreateRoomCommand, Room>(request);

            room.CreatedDate = _clock.UtcNow();

            await _roomRepository.CreateAsync(room).ConfigureAwait(false);

            var evt = _mapper.Map <CreateRoomCommand, RoomCreatedEvent>(request);

            await _eventPublisher.Publish(evt).ConfigureAwait(false);

            return(Unit.Value);
        }
예제 #7
0
        public async Task <Unit> Handle(IllMakeCommand request, CancellationToken cancellationToken)
        {
            var model = new IllMake
            {
                Id          = request.Id,
                RunId       = request.RunId,
                UserId      = request.UserId,
                CreatedDate = _clock.UtcNow()
            };

            //todo: event
            await _repository.CreateAsync(model);

            return(Unit.Value);
        }
예제 #8
0
        public async Task <Unit> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var order = _mapper.Map <CreateOrderCommand, Order>(request);

            order.CreatedDate = _clock.UtcNow();

            await _orderRepository.CreateAsync(order).ConfigureAwait(false);

            var evt = _mapper.Map <Order, OrderPlacedEvent>(order);

            evt.State = request.State;

            await _eventPublisher.Publish(evt).ConfigureAwait(false);

            return(Unit.Value);
        }
예제 #9
0
 public WordCache(
     IUnitOfWork unitOfWork,
     ILogger <WordCache> logger,
     IDistributedCache distributedCache,
     ISystemClock systemClock,
     //ApplicationSettings applicationSettings,
     IMemoryCache memoryCache)
     : base(
         distributedCache,
         "Words",
         new DistributedCacheEntryOptions()
 {
     AbsoluteExpiration = systemClock.UtcNow().Add(TimeSpan.FromDays(1)),
 },
         (words) => words.Select(x => new WordDto(x.Word)),
         memoryCache,
         CacheInMemoryOffload.Singleton,
         TimeSpan.FromMinutes(1)
         )
 {
     this.unitOfWork  = unitOfWork;
     this.logger      = logger;
     this.systemClock = systemClock;
 }