Beispiel #1
0
        public async Task <ICommandResult> AddOption(string groupName, string optionName)
        {
            if (string.IsNullOrWhiteSpace(groupName) || string.IsNullOrWhiteSpace(optionName))
            {
                return(Response(ErrorStrings.AddOption_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.AddOption_GroupInvalidName(groupName), ResponseType.User));
            }

            var command =
                new CreateOptionCommand(
                    id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                    userId: context.User.Id,
                    groupId: group.Id,
                    name: optionName);

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

            return(Response(ResponseStrings.OptionAddedToGroup(optionName, group.Name), ResponseType.User));
        }