public static void ExecuteBot(int id) { var ctx = new RedditRSSEntities(); ExecuteBotInternal(ctx, id); ctx.SaveChanges(); }
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(); }
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 }; ctx.RedditRSSBotDatas.Add(botData); ctx.SaveChanges(); var manager = RedditRSSBotManager.Instance; manager.AddBot(botData.CreateBot()); ucBotList.DataBind(); }
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("~/"); } }
protected void btnLogin_Click(object sender, EventArgs e) { var returnUrl = Request.QueryString["returnUrl"]; bool loginValid = false; var userName = tbUsername.Text; var pw = tbPassword.Text; var ctx = new RedditRSSEntities(); var appUser = ctx.AppUsers.Where(x => x.Username == userName).FirstOrDefault(); if (appUser != null) { var validPW = CryptUtil.ValidatePassword(pw, appUser.HashedPassword); if (validPW) { loginValid = true; Session[AppConstants.SessionKeys.LOGGED_IN_USER_ID] = appUser.ID; Session[AppConstants.SessionKeys.LOGGED_IN_USER_NAME] = appUser.Username; } } if (!loginValid) { lblMessage.Text = "Login invalid. Please check the username and password"; } else { Response.Redirect("~/" + (returnUrl == null ? "": returnUrl)); } }
public IQueryable <RedditUser> ddlUsers_GetData() { var ctx = new RedditRSSEntities(); if (UserLoggedIn) { return(ctx.RedditUsers.Where(x => x.AppUserID == CurrentUserID).AsQueryable()); } return(null); }
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(); }
private static void ExecuteBotInternal(RedditRSSEntities ctx, int id) { var botData = ctx.RedditRSSBotDatas.Where(x => x.ID == id).FirstOrDefault(); if (botData != null) { var bot = new RedditRSSBot(botData); var newSubmissions = bot.CheckAndSubmitNews(); newSubmissions.ToList().ForEach(x => ctx.RedditSubmissions.Add(x)); } }
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(); }
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("~/"); }
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(); } }
public IQueryable <RedditRSSBotData> gvBots_GetData() { var ctx = new RedditRSSEntities(); var results = new List <RedditRSSBotData>().AsQueryable(); if (this.DisplayMode == BotListDisplayMode.SingleUser) { results = ctx.RedditRSSBotDatas.Where(x => x.RedditUser.AppUserID == (int)CurrentUserID); } else if (DisplayMode == BotListDisplayMode.All) { results = ctx.RedditRSSBotDatas; } else if (DisplayMode == BotListDisplayMode.CurrentlyRunning) { results = ctx.RedditRSSBotDatas.Where(x => x.StatusTypeID == 2); } return(results); }
private List <RedditUser> GetRedditUsers() { var ctx = new RedditRSSEntities(); return(ctx.RedditUsers.ToList()); }