예제 #1
0
        public ActionResult Index()
        {
            // get users bot settings
            var userBotSettings = ContextService.GetBotUserSettingsForUser(ContextService.GetUser(User.Identity.Name));
            var userLoyalty     = ContextService.GetBotChannelSettings(ContextService.GetUser(User.Identity.Name)).Loyalty;
            var timers          = ContextService.GetTimers(ContextService.GetUser(User.Identity.Name));
            var triggers        = ContextService.GetTriggers(ContextService.GetUser(User.Identity.Name));
            var bannedWords     = ContextService.GetBotChannelSettings(ContextService.GetUser(User.Identity.Name))
                                  .BannedWords;

            if (bannedWords == null)
            {
                bannedWords = new List <BannedWord>();
            }
            var stringBannedWords = new List <string>();

            foreach (var bannedWord in bannedWords)
            {
                stringBannedWords.Add(bannedWord.Word);
            }

            var loyalty            = userLoyalty ?? new Loyalty();
            var dashboardViewModel = new DashboardViewModel()
            {
                BotUserSettings = userBotSettings,
                LoyaltySettings = loyalty,
                Timers          = timers,
                Triggers        = triggers,
                BannedWords     = string.Join(",", stringBannedWords)
            };

            // send user to bot preferences page if not set
            if (string.IsNullOrWhiteSpace(userBotSettings.BotChannel) || string.IsNullOrWhiteSpace(userBotSettings.BotUsername) ||
                string.IsNullOrWhiteSpace(userBotSettings.BotUsername))
            {
                RedirectToAction("Preferences", new { message = "Please set your bot account and channel information" });
            }

            // assert that
            return(View(dashboardViewModel));
        }