public static object PostUserGameConnectionData(string ID, DataConnectionType TypeID, Hashtable Data) { try { GamervineDataContext dContext = new GamervineDataContext(); var gvUser = from usc in dContext.UserSocialConnections where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode() select usc; if (gvUser.Count() > 0) { var dGamertag = from gt in dContext.Gamertags where gt.Type == TypeID.GetHashCode() && gt.UserId == gvUser.First().UserId select gt; bool isStatusJobEnabled = false; bool isSummaryJobEnabled = false; bool isFacebookEnabled = false; //bool isTagInsert = false; if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"])["Enabled"]) == 1) { isStatusJobEnabled = true; } if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"])["Enabled"]) == 1) { isSummaryJobEnabled = true; } if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"])["Enabled"]) == 1) { isFacebookEnabled = true; } Gamertag gamertag = new Gamertag(); if (dGamertag.Count() == 0) { //isTagInsert = true; gamertag = Insert(gvUser.First().UserId, TypeID.GetHashCode(), Data); } else { gamertag = dGamertag.First(); gamertag.Tag = Utility.ToString(((Hashtable)Data["Data"])["Tag"]); var statusPost = from j in dContext.Jobs where j.TagId == gamertag.TagId && j.Type == JobTypes.Status.GetHashCode() select j; var summaryPost = from j in dContext.Jobs where j.TagId == gamertag.TagId && j.Type == JobTypes.Summary.GetHashCode() select j; var fbConnection = from gtsc in dContext.GamertagSocialConnections where gtsc.TagId == gamertag.TagId && gtsc.UserSocialConnectionId == gvUser.First().UserSocialConnectionId select gtsc; if (isStatusJobEnabled) { Hashtable statusData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"]; Job statusJob = new Job(); //We have an existing status job and the enabled flag is true - persist settings if (statusPost.Count() > 0) { statusJob = statusPost.First(); } else { statusJob.JobId = Guid.NewGuid().ToString(); statusJob.LastRunTime = null; statusJob.TagId = gamertag.TagId; statusJob.PostFormat = string.Empty; statusJob.Type = JobTypes.Status.GetHashCode(); dContext.Jobs.InsertOnSubmit(statusJob); } statusJob.Frequency = Utility.ToInt(statusData["Frequency"]); statusJob.FrequencyUnits = Utility.ToInt(statusData["FrequencyUnits"]); statusJob.NextRunTime = statusJob.CalculateNextRunTime(); } else { //The enabled flag is false and if we have an existing status job - delete the job if (statusPost.Count() > 0) { dContext.Jobs.DeleteOnSubmit(statusPost.First()); } } if (isSummaryJobEnabled) { Hashtable summaryData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"]; Job summaryJob = new Job(); //We have an existing summary job and the enabled flag is true - persist settings if (summaryPost.Count() > 0) { summaryJob = summaryPost.First(); } else { summaryJob.JobId = Guid.NewGuid().ToString(); summaryJob.LastRunTime = null; summaryJob.TagId = gamertag.TagId; summaryJob.PostFormat = string.Empty; summaryJob.Type = JobTypes.Summary.GetHashCode(); dContext.Jobs.InsertOnSubmit(summaryJob); } summaryJob.Frequency = Utility.ToInt(summaryData["Frequency"]); summaryJob.FrequencyUnits = Utility.ToInt(summaryData["FrequencyUnits"]); summaryJob.NextRunTime = summaryJob.CalculateNextRunTime(); } else { //The enabled flag is false and if we have an existing summary job - delete the job if (summaryPost.Count() > 0) { dContext.Jobs.DeleteOnSubmit(summaryPost.First()); } } if (isFacebookEnabled) { Hashtable fbData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"]; GamertagSocialConnection fbSocialConn = new GamertagSocialConnection(); //We have an existing summary job and the enabled flag is true - persist settings if (fbConnection.Count() > 0) { fbSocialConn = fbConnection.First(); } else { fbSocialConn.TagId = gamertag.TagId; fbSocialConn.UserSocialConnectionId = gvUser.First().UserSocialConnectionId; dContext.GamertagSocialConnections.InsertOnSubmit(fbSocialConn); } } else { //The enabled flag is false and if we have an existing facebook connection - delete the connection if (fbConnection.Count() > 0) { dContext.GamertagSocialConnections.DeleteOnSubmit(fbConnection.First()); } } } dContext.SubmitChanges(); return(string.Empty); } else { return new { Error = "Social connection ID \"" + ID + "\" does not exist." } }; } catch (Exception ex) { return(new { Error = ex.ToString() }); } }
public static object PostUserGameConnectionData(string ID, DataConnectionType TypeID, Hashtable Data) { try { GamervineDataContext dContext = new GamervineDataContext(); var gvUser = from usc in dContext.UserSocialConnections where usc.ConnectionUserId == ID && usc.Type == TypeID.GetHashCode() select usc; if (gvUser.Count() > 0) { var dGamertag = from gt in dContext.Gamertags where gt.Type == TypeID.GetHashCode() && gt.UserId == gvUser.First().UserId select gt; bool isStatusJobEnabled = false; bool isSummaryJobEnabled = false; bool isFacebookEnabled = false; //bool isTagInsert = false; if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"])["Enabled"]) == 1) isStatusJobEnabled = true; if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"])["Enabled"]) == 1) isSummaryJobEnabled = true; if (Utility.ToInt(((Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"])["Enabled"]) == 1) isFacebookEnabled = true; Gamertag gamertag = new Gamertag(); if (dGamertag.Count() == 0) { //isTagInsert = true; gamertag = Insert(gvUser.First().UserId, TypeID.GetHashCode(), Data); } else { gamertag = dGamertag.First(); gamertag.Tag = Utility.ToString(((Hashtable)Data["Data"])["Tag"]); var statusPost = from j in dContext.Jobs where j.TagId == gamertag.TagId && j.Type == JobTypes.Status.GetHashCode() select j; var summaryPost = from j in dContext.Jobs where j.TagId == gamertag.TagId && j.Type == JobTypes.Summary.GetHashCode() select j; var fbConnection = from gtsc in dContext.GamertagSocialConnections where gtsc.TagId == gamertag.TagId && gtsc.UserSocialConnectionId == gvUser.First().UserSocialConnectionId select gtsc; if (isStatusJobEnabled) { Hashtable statusData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Status"]; Job statusJob = new Job(); //We have an existing status job and the enabled flag is true - persist settings if (statusPost.Count() > 0) statusJob = statusPost.First(); else { statusJob.JobId = Guid.NewGuid().ToString(); statusJob.LastRunTime = null; statusJob.TagId = gamertag.TagId; statusJob.PostFormat = string.Empty; statusJob.Type = JobTypes.Status.GetHashCode(); dContext.Jobs.InsertOnSubmit(statusJob); } statusJob.Frequency = Utility.ToInt(statusData["Frequency"]); statusJob.FrequencyUnits = Utility.ToInt(statusData["FrequencyUnits"]); statusJob.NextRunTime = statusJob.CalculateNextRunTime(); } else { //The enabled flag is false and if we have an existing status job - delete the job if (statusPost.Count() > 0) dContext.Jobs.DeleteOnSubmit(statusPost.First()); } if (isSummaryJobEnabled) { Hashtable summaryData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["Jobs"])["Summary"]; Job summaryJob = new Job(); //We have an existing summary job and the enabled flag is true - persist settings if (summaryPost.Count() > 0) summaryJob = summaryPost.First(); else { summaryJob.JobId = Guid.NewGuid().ToString(); summaryJob.LastRunTime = null; summaryJob.TagId = gamertag.TagId; summaryJob.PostFormat = string.Empty; summaryJob.Type = JobTypes.Summary.GetHashCode(); dContext.Jobs.InsertOnSubmit(summaryJob); } summaryJob.Frequency = Utility.ToInt(summaryData["Frequency"]); summaryJob.FrequencyUnits = Utility.ToInt(summaryData["FrequencyUnits"]); summaryJob.NextRunTime = summaryJob.CalculateNextRunTime(); } else { //The enabled flag is false and if we have an existing summary job - delete the job if (summaryPost.Count() > 0) dContext.Jobs.DeleteOnSubmit(summaryPost.First()); } if (isFacebookEnabled) { Hashtable fbData = (Hashtable)((Hashtable)((Hashtable)Data["Data"])["GamertagSocialConnections"])["Facebook"]; GamertagSocialConnection fbSocialConn = new GamertagSocialConnection(); //We have an existing summary job and the enabled flag is true - persist settings if (fbConnection.Count() > 0) fbSocialConn = fbConnection.First(); else { fbSocialConn.TagId = gamertag.TagId; fbSocialConn.UserSocialConnectionId = gvUser.First().UserSocialConnectionId; dContext.GamertagSocialConnections.InsertOnSubmit(fbSocialConn); } } else { //The enabled flag is false and if we have an existing facebook connection - delete the connection if (fbConnection.Count() > 0) dContext.GamertagSocialConnections.DeleteOnSubmit(fbConnection.First()); } } dContext.SubmitChanges(); return string.Empty; } else return new { Error = "Social connection ID \"" + ID + "\" does not exist." }; } catch (Exception ex) { return new { Error = ex.ToString() }; } }