예제 #1
0
        public string CreateRoom([FromBody] RoomSettingsDto roomSettings)
        {
            var themes = roomSettings.ThemesIds.Count == 0
                ? themeRepository.GetDefaultThemes()
                : roomSettings.ThemesIds.Select(id => themeRepository.FindById(id)).ToList();

            var settings = mapper.Map <RoomSettings>(roomSettings);
            var words    = GetMixedWordsFromThemes(themes);
            var newRoom  = new Room
            {
                Game     = CreateGame(words, settings),
                Settings = settings
            };

            roomRepository.Insert(newRoom);

            foreach (var theme in themes)
            {
                var themeRoomSettings = new ThemeRoomSettings
                {
                    RoomSettingsId = newRoom.Settings.Id, ThemeId = theme.Id
                };
                settings.ThemeRoomSettings.Add(themeRoomSettings);
                theme.ThemeRoomSettings.Add(themeRoomSettings);
            }

            return(newRoom.Id.ToString());
        }