コード例 #1
0
        /// <summary>
        /// Set users bot settings
        /// </summary>
        /// <param name="botUserSettings"></param>
        /// <returns>BotUserSettings</returns>
        public BotUserSettings SetBotUserSettingsForUser(BotUserSettings botUserSettings)
        {
            if (botUserSettings?.User == null)
            {
                return(null);
            }

            try
            {
                var dbSettings = Context.BotUserSettings.FirstOrDefault(u => u.User.Id == botUserSettings.User.Id);

                if (dbSettings != null)
                {
                    dbSettings.BotChannel   = botUserSettings.BotChannel;
                    dbSettings.BotUsername  = botUserSettings.BotUsername;
                    dbSettings.BotPassword  = botUserSettings.BotPassword;
                    dbSettings.ChannelToken = botUserSettings.ChannelToken;
                }
                else
                {
                    Context.BotUserSettings.Add(botUserSettings);
                }

                Context.SaveChanges();
            }
            catch (Exception e)
            {
                throw;
            }

            return(botUserSettings);
        }
コード例 #2
0
        public ActionResult PreferencesSave(string botusername, string passwordinput, string channel, string channelToken)
        {
            try
            {
                var botUserSettings = new BotUserSettings()
                {
                    User         = ContextService.GetUser(User.Identity.Name),
                    BotUsername  = botusername ?? "",
                    BotPassword  = passwordinput ?? "",
                    BotChannel   = channel ?? "",
                    ChannelToken = channelToken ?? ""
                };

                ContextService.SetBotUserSettingsForUser(botUserSettings);

                if (!ContextService.HasSystemTriggers(User.Identity.Name))
                {
                    ContextService.AddSystemTriggers(User.Identity.Name);
                }

                return(Json(new { data = "1", message = "Saved!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { data = "-1", message = "Error saving: " + e.Message }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        /// <summary>
        /// Get a users BotUserSettings
        /// </summary>
        /// <param name="user"></param>
        /// <returns>BotUsersSettings</returns>
        public BotUserSettings GetBotUserSettingsForUser(ApplicationUser user)
        {
            if (user == null)
            {
                //throw new Exception("No user object given");
                return(null);
            }

            Context = new ApplicationDbContext();

            var botUserSettings = Context.BotUserSettings.FirstOrDefault(b => b.User.Id == user.Id);

            if (botUserSettings == null)
            {
                botUserSettings = new BotUserSettings()
                {
                    BotUsername = "",
                    BotPassword = "",
                    BotChannel  = ""
                };
            }

            // Check if user has botchannelsettings stored in db
            if (GetBotChannelSettings(user) == null)
            {
                SetInitialBotChannelSettings(user);
            }


            return(botUserSettings);
        }