public string DoLogin(string name, string email) { if (email == (string)Session["Email"]) { return(""); } Session["Admin"] = null; Session["Email"] = email; Social_PresenceEntities model = new Social_PresenceEntities(); Contributor c = new Contributor(); c.name = name; c.email = email; Contributor contr = HasSuchEmail(model, c); if (contr == null) { model.Contributors.Add(c); model.SaveChanges(); } else { if (contr.admin) { Session["Admin"] = true; } } return("true"); }
private static Contributor HasSuchEmail(Social_PresenceEntities model, Contributor c) { foreach (Contributor contr in model.Contributors) { if (contr.email == c.email) { return(contr); } } return(null); }
/// <summary> /// Synchronizes posts retrived from the ICommunityClient to the database /// </summary> /// <param name="client">Social presence data client</param> /// <param name="model">Database reference</param> /// <param name="filter">Must return true for the pages whose posts need to be synced. See predefined filters in Utils.</param> public static void SyncPosts(ICommunityClient client, Social_PresenceEntities model, PageSyncFilter filter) { //HashSet<String> addedIds = new HashSet<string>(); Stopwatch executionSw = new Stopwatch(); Stopwatch saveSw = new Stopwatch(); executionSw.Start(); var pages = new List <facebook_page>(model.facebook_page); pages.Reverse(); int i = 0; int addedPosts = 0; int existingPosts = 0; int failedToStorePosts = 0; var postIds = model.posts.Select(p => p.id); var postIdSet = new HashSet <string>(postIds); foreach (var page in pages) { int addedPostsForPage = 0; if (page.url == null || !filter(model, page)) { continue; } try { Console.WriteLine("Retrieving posts for page {0}; id: {1}", page.url, page.id); Console.WriteLine("Type: {0}", page.type); List <post> posts = client.GetPosts(page.url, page.contributor_email, page.id, 1000 /* limit */, postIdSet); foreach (var newPost in posts) { model.posts.Add(newPost); Console.WriteLine("Added new post with ID: " + newPost.id); ++addedPostsForPage; } } catch (Exception e) { Console.WriteLine("Error retrieving posts for page {0}: {1}.", page.url, e); } Console.WriteLine("Saving posts ..."); saveSw.Restart(); try { model.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); RejectChanges(model); failedToStorePosts += addedPostsForPage; addedPostsForPage = 0; } saveSw.Stop(); Console.WriteLine("Saved posts for {0}", saveSw.Elapsed); ++i; Console.WriteLine("Processed {0} pages out of {3} for {1}. {2} sec per page", i, executionSw.Elapsed, executionSw.Elapsed.TotalSeconds / i, pages.Count); addedPosts += addedPostsForPage; Console.WriteLine("Added posts: {0}, Existing posts: {1}. Failed posts: {2}", addedPosts, existingPosts, failedToStorePosts); } executionSw.Stop(); }