Beispiel #1
0
        public async Task <ICommandResult> RemoveOption(string groupName, string optionName)
        {
            if (string.IsNullOrWhiteSpace(groupName) || string.IsNullOrWhiteSpace(optionName))
            {
                return(Response(ErrorStrings.RemoveOption_BadArguments(), ResponseType.User));
            }

            var context = await GetContextAsync().ConfigureAwait(false);

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

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

            var option = group.Options.FirstOrDefault(o => o.Name.Equals(optionName));

            if (option == null)
            {
                return(Response(ErrorStrings.RemoveOption_UnknownOption(optionName), ResponseType.User));
            }

            var command = new DeleteOptionCommand(option.Id, context.User.Id);

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

            return(Response(ResponseStrings.OptionRemoved(optionName, groupName), ResponseType.User));
        }
Beispiel #2
0
        public async Task <Unit> Handle(DeleteOptionCommand request, CancellationToken cancellationToken)
        {
            await _optionsRepository.DeleteAsync(request.OptionId);

            return(Unit.Value);
        }