コード例 #1
0
ファイル: BotList.ascx.cs プロジェクト: DrLeh/reddit-rss-bot
        protected void gvBots_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var id = int.Parse((string)e.CommandArgument);
            var ctx = new RedditRSSEntities();

            if (e.CommandName == "StartBot")
            {
                var bot = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                if (bot != null)
                    bot.StatusTypeID = 2;
                ctx.SaveChanges();
            }
            else if (e.CommandName == "StopBot")
            {
                var bot = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                if (bot != null)
                    bot.StatusTypeID = 3;
                ctx.SaveChanges();
            }
            else if (e.CommandName == "DeleteBot")
            {
                var botToRemove = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault();
                ctx.RedditRSSBotDatas.Remove(botToRemove);
                ctx.SaveChanges();
            }
            gvBots.DataBind();
        }
コード例 #2
0
ファイル: Register.aspx.cs プロジェクト: DrLeh/reddit-rss-bot
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     var username = tbUsername.Text;
     var password = tbPassword.Text;
     var passwordConfirm = tbPasswordConfirm.Text;
     if (username == null && password == null && passwordConfirm == null)
     {
         lblMessage.Text = "All fields are required";
     }
     else if (password != passwordConfirm)
     {
         lblMessage.Text = "Password Fields don't match!";
     }
     else
     {
         var ctx = new RedditRSSEntities();
         var appUser = new AppUser();
         appUser.Username = username;
         appUser.Password = password;
         appUser.HashPassword();
         ctx.AppUsers.Add(appUser);
         ctx.SaveChanges();
         Session[AppConstants.SessionKeys.LOGGED_IN_USER_ID] = appUser.ID;
         Session[AppConstants.SessionKeys.LOGGED_IN_USER_NAME] = appUser.Username;
         Response.Redirect("~/");
     }
 }
コード例 #3
0
 public static void ExecuteAllRunningBots()
 {
     var ctx = new RedditRSSEntities();
     var botDatas = ctx.RedditRSSBotDatas.Where(x => x.StatusTypeID == 2).Select(x => x.ID);
     foreach (var botDataID in botDatas)
     {
         ExecuteBotInternal(ctx, botDataID);
     }
     ctx.SaveChanges();
 }
コード例 #4
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     var user = new RedditUser();
     user.Username = tbUsername.Text;
     user.Password = tbPassword.Text;
     user.AppUserID = CurrentUserID;
     var ctx = new RedditRSSEntities();
     ctx.RedditUsers.Add(user);
     ctx.SaveChanges();
     gvUsers.DataBind();
 }
コード例 #5
0
ファイル: Manage.aspx.cs プロジェクト: DrLeh/reddit-rss-bot
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     var userID = (int)CurrentUserID;
     var ctx = new RedditRSSEntities();
     var appUser = ctx.AppUsers.Where(x => x.ID == userID).FirstOrDefault();
     var redditUsers = ctx.RedditUsers.Where(x => x.AppUserID == userID).ToList();
     var bots = ctx.RedditRSSBotDatas.Where(x => redditUsers.Any(y => x.RedditUserID == y.ID)).ToList();
     bots.ForEach(x => ctx.RedditRSSBotDatas.Remove(x));
     redditUsers.ForEach(x => ctx.RedditUsers.Remove(x));
     ctx.AppUsers.Remove(appUser);
     ctx.SaveChanges();
     Response.Redirect("~/");
 }
コード例 #6
0
        protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteUser")
            {
                var id = int.Parse((string)e.CommandArgument);
                var ctx = new RedditRSSEntities();
                var user = ctx.RedditUsers.Where(x => x.ID == id).FirstOrDefault();
                var botDatas = ctx.RedditRSSBotDatas.Where(x => x.RedditUserID == id).ToList();

                var botsToRemove = ctx.RedditRSSBotDatas.Where(x => x.RedditUserID == id).ToList();

                botDatas.ForEach(x => ctx.RedditRSSBotDatas.Remove(x));
                ctx.RedditUsers.Remove(user);
                ctx.SaveChanges();
                gvUsers.DataBind();
            }
        }
コード例 #7
0
        protected void btnAddFeed_Click(object sender, EventArgs e)
        {
            var feed = tbFeedUrl.Text;
            var subreddit = tbSubReddit.Text;
            var interval = int.Parse(tbInterval.Text);

            var ctx = new RedditRSSEntities();
            var selectedUserID = int.Parse(ddlUsers.SelectedValue);
            var user = ctx.RedditUsers.Where(x => x.ID == selectedUserID).FirstOrDefault();
            var botData = new RedditRSSBotData()
            {
                FeedUrl = feed,
                Subreddit = subreddit,
                RedditUser = user,
                Interval = interval,
                StatusTypeID=1
            };
            ctx.RedditRSSBotDatas.Add(botData);
            ctx.SaveChanges();

            ucBotList.DataBind();
        }
コード例 #8
0
 public static void ExecuteBot(int id)
 {
     var ctx = new RedditRSSEntities();
     ExecuteBotInternal(ctx, id);
     ctx.SaveChanges();
 }