private static void AddRemoveSubscription(int subTypeId, string username, bool add) { string settingKey = EMAIL_SUB_SETTING_KEY_PREFIX + subTypeId; var data = LibCommon.DBModel(); // first remove any existing var existingSubs = data.userSettings .Where(x => x.active_flag && x.settingKey == settingKey && x.username == username); foreach (var sub in existingSubs) { sub.active_flag = false; sub.update_dt = DateTime.Now; } // if add, then add it if (add) { db.userSetting sub = new db.userSetting(); sub.settingKey = settingKey; sub.settingValue = string.Empty; sub.username = username; sub.insert_dt = DateTime.Now; sub.update_dt = DateTime.Now; sub.active_flag = true; data.userSettings.InsertOnSubmit(sub); } data.SubmitChanges(); }
public static db.user[] GetSubscribedUsers(EmailSubscriptionType subType) { var names = LibCommon.DBModel().userSettings .Where(x => x.settingKey == EMAIL_SUB_SETTING_KEY_PREFIX + (int)subType && x.active_flag) .Select(x => x.username) .ToArray(); return(LibCommon.DBModel().users.Where(x => names.Contains(x.name) && x.email != null && x.IsActive).OrderBy(u => u.registration_dt).ToArray()); }
public static string LinkToUnsubscripe(string userKey, int subTypeId) { string result = LibCommon.WebsiteUrlRoot() + "UpdateFromLink.aspx?"; result += "commandType=1"; result += "&emailType=" + subTypeId; result += "&userKey=" + userKey; return(result); }
public static string GetEmailSubDescription(int subTypeId) { var sub = LibCommon.DBModel().emailSubscriptionTypes.FirstOrDefault(x => x.Id == subTypeId); if (sub != null) { return(sub.Name); } else { return(null); } }
private void DoUpdateNFLMatchupsESPN() { try { System.Net.WebClient client = new System.Net.WebClient(); string json = client.DownloadString("http://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard"); API.ESPN.Feed model = Newtonsoft.Json.JsonConvert.DeserializeObject <API.ESPN.Feed>(json); var data = DBModel(); int[] nflYears = data.NFL_years.Where(x => x.sport_id == 100).Select(x => x.id).ToArray(); int[] nflWeeks = data.NFL_weeks.Where(x => nflYears.Contains(x.year_id.Value)).Select(x => x.week).ToArray(); var matchupsWithoutWinner = data.NFL_Matchups.Where(x => x.winner == null && nflWeeks.Contains(x.week) && model.week.number == x.year_week).ToList(); foreach (var matchup in matchupsWithoutWinner) { int week = matchup.year_week ?? matchup.week; int yearId = data.NFL_weeks.First(x => x.week == matchup.week).year_id ?? 1; int year = data.NFL_years.First(x => x.id == yearId).year; API.ESPN.Event apiMatchup = model.events.FirstOrDefault(m => CheckForWeirdName(m.competitions.First().competitors.First(c => c.homeAway == "home").team.shortDisplayName) == matchup.home && CheckForWeirdName(m.competitions.First().competitors.First(c => c.homeAway == "away").team.shortDisplayName) == matchup.away); if (apiMatchup != null) { UpdateMatchup(matchup, apiMatchup); } } if (_changesMade) { data.SubmitChanges(); } checkIfWeeksNeedToBeClosed(); } catch (Exception ex) { try { //if (IsAppInTestMode()) LibCommon.SendEmail("*****@*****.**", "Exception in DoUpdateNFLMatchupsESPN()", ex.ToString(), "EricWrightSite"); } catch { } } }
public static bool UpdateNFLMatchups(bool async) { // note: async true will always return changeMade false. if calling async should disregard response. _changesMade = false; LibCommon m = new LibCommon(); System.Threading.Thread t = new System.Threading.Thread(m.DoUpdateNFLMatchupsESPN); t.Start(); if (!async) { while (t.IsAlive) { System.Threading.Thread.Sleep(1); } } return(_changesMade); }
public static int[] AllSubscriptionTypeIds() { return(LibCommon.DBModel().emailSubscriptionTypes.Select(x => x.Id).ToArray()); }
public static bool UserHasSubscription(int subTypeId, string username) { return(LibCommon.DBModel().userSettings.Count(x => x.settingKey == EMAIL_SUB_SETTING_KEY_PREFIX + subTypeId && x.username == username && x.active_flag) > 0); }
private void DoUpdateNFLMatchupsJson() { try { System.Net.WebClient client = new System.Net.WebClient(); API.NFL.NFL_API_Json model = new API.NFL.NFL_API_Json(); string json = client.DownloadString("http://static.nfl.com/liveupdate/scores/scores.json"); model.Matchups = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, API.NFL.Matchup> >(json); var data = DBModel(); int[] nflYears = data.NFL_years.Where(x => x.sport_id == 100).Select(x => x.id).ToArray(); int[] nflWeeks = data.NFL_weeks.Where(x => nflYears.Contains(x.year_id.Value)).Select(x => x.week).ToArray(); var matchupsWithoutWinner = data.NFL_Matchups.Where(x => x.winner == null && nflWeeks.Contains(x.week)).ToList(); bool changesMade = false; foreach (var matchup in matchupsWithoutWinner) { int week = matchup.year_week ?? matchup.week; int yearId = data.NFL_weeks.First(x => x.week == matchup.week).year_id ?? 1; int year = data.NFL_years.First(x => x.id == yearId).year; //System.Xml.XmlNode node = null; KeyValuePair <string, API.NFL.Matchup> apiMatchup = new KeyValuePair <string, API.NFL.Matchup>(); // regular season //if (matchup.NFL_week.weekTypeId == (int)WeekTypes.RegularSeason) //{ apiMatchup = model.Matchups.FirstOrDefault(m => m.Value.away.abbr == GetAbbreviation(matchup.away) && m.Value.home.abbr == GetAbbreviation(matchup.home)); //node = xDocRegSeason.SelectSingleNode("//ss/gms[@w='" + week + "' and @y='" + year + "' and @t='R']/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); if (apiMatchup.Key != null) { UpdateMatchup(matchup, apiMatchup); changesMade = true; } //} // pre season //if (matchup.NFL_week.weekTypeId == (int)WeekTypes.PreSeason) //{ // node = xDocRegSeason.SelectSingleNode("//ss/gms[@w='" + week + "' and @y='" + year + "' and @t='P']/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); // if (node != null) // { // UpdateMatchup(matchup, node); // changesMade = true; // } //} // post season (playoffs and super bowl) //if (matchup.NFL_week.weekTypeId == (int)WeekTypes.PostSeason) //{ // node = xDocPostSeason.SelectSingleNode("//ss/gms[@y='" + year + "' and (@t='POST' or @t='PRO')]/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); // if (node != null) // { // UpdateMatchup(matchup, node); // changesMade = true; // } //} //// Pro Bowl //if (matchup.home == "AFC" || matchup.home == "NFC") //{ // node = xDocPostSeason.SelectSingleNode("//ss/gms[@y='" + year + "' and @t='POST']/g[@hnn = 'afc pro bowl' or @vnn = 'afc pro bowl']"); // if (node != null) // { // UpdateMatchup(matchup, node); // changesMade = true; // } //} } if (changesMade) { data.SubmitChanges(); } checkIfWeeksNeedToBeClosed(); } catch (Exception ex) { try { //if (IsAppInTestMode()) LibCommon.SendEmail("*****@*****.**", "Exception in DoUpdateNFLMatchupsJson()", ex.ToString(), "EricWrightSite"); } catch { } } }
private void DoUpdateNFLMatchups() { try { var data = DBModel(); int[] nflYears = data.NFL_years.Where(x => x.sport_id == 100).Select(x => x.id).ToArray(); int[] nflWeeks = data.NFL_weeks.Where(x => nflYears.Contains(x.year_id.Value)).Select(x => x.week).ToArray(); var matchupsWithoutWinner = data.NFL_Matchups.Where(x => x.winner == null && nflWeeks.Contains(x.week)); bool changesMade = false; System.Net.WebClient wc = new System.Net.WebClient(); System.Xml.XmlDocument xDocRegSeason = new System.Xml.XmlDocument(); xDocRegSeason.LoadXml(wc.DownloadString("http://www.nfl.com/liveupdate/scorestrip/ss.xml")); System.Xml.XmlDocument xDocPostSeason = new System.Xml.XmlDocument(); xDocPostSeason.LoadXml(wc.DownloadString("http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml")); foreach (var matchup in matchupsWithoutWinner) { int week = matchup.year_week ?? matchup.week; int yearId = data.NFL_weeks.First(x => x.week == matchup.week).year_id ?? 1; int year = data.NFL_years.First(x => x.id == yearId).year; System.Xml.XmlNode node = null; // regular season if (matchup.NFL_week.weekTypeId == (int)WeekTypes.RegularSeason) { node = xDocRegSeason.SelectSingleNode("//ss/gms[@w='" + week + "' and @y='" + year + "' and @t='R']/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); if (node != null) { UpdateMatchup(matchup, node); changesMade = true; } } // pre season if (matchup.NFL_week.weekTypeId == (int)WeekTypes.PreSeason) { node = xDocRegSeason.SelectSingleNode("//ss/gms[@w='" + week + "' and @y='" + year + "' and @t='P']/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); if (node != null) { UpdateMatchup(matchup, node); changesMade = true; } } // post season (playoffs and super bowl) if (matchup.NFL_week.weekTypeId == (int)WeekTypes.PostSeason) { node = xDocPostSeason.SelectSingleNode("//ss/gms[@y='" + year + "' and (@t='POST' or @t='PRO')]/g[@hnn='" + matchup.home.ToLower() + "' and @vnn='" + matchup.away.ToLower() + "']"); if (node != null) { UpdateMatchup(matchup, node); changesMade = true; } } //// Pro Bowl //if (matchup.home == "AFC" || matchup.home == "NFC") //{ // node = xDocPostSeason.SelectSingleNode("//ss/gms[@y='" + year + "' and @t='POST']/g[@hnn = 'afc pro bowl' or @vnn = 'afc pro bowl']"); // if (node != null) // { // UpdateMatchup(matchup, node); // changesMade = true; // } //} } if (changesMade) { data.SubmitChanges(); } checkIfWeeksNeedToBeClosed(); } catch (Exception ex) { try { //if (IsAppInTestMode()) LibCommon.SendEmail("*****@*****.**", "Exception in UpdateNFLMatchups()", ex.ToString(), "EricWrightSite"); } catch { } } }