protected void Page_Load(object sender, EventArgs e) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagGreatest); JObject user = facebook.GetObject("me", null); MixmagGreatestVoteSet vs = new MixmagGreatestVoteSet(new Query(new Q(MixmagGreatestVote.Columns.FacebookUid, facebook.Uid))); if (vs.Count > 0) { try { Update u = new Update(); u.Table = TablesEnum.MixmagGreatestDj; u.Changes.Add(new Assign.Subtraction(MixmagGreatestDj.Columns.TotalVotes, 1)); u.Where = new Q(MixmagGreatestDj.Columns.K, vs[0].MixmagGreatestDjK); u.Run(); } catch { } vs[0].Delete(); Response.Write("Done."); } else Response.Write("Nothing to delete!"); }
protected void Page_Load(object sender, EventArgs e) { Query q = new Query(); q.ReturnCountOnly = true; MixmagGreatestVoteSet vs = new MixmagGreatestVoteSet(q); Response.Write(vs.Count); }
public static Hashtable VoteNow(int mixmagGreatestDjK, string facebookSource, bool facebookMessage) { try { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagGreatest); JObject user = facebook.GetObject("me", null); //string email = user.Value<string>("email"); string firstName = user.Value<string>("first_name"); string lastName = user.Value<string>("last_name"); Hashtable ret = new Hashtable(); if (DateTime.Now > new DateTime(2011, 12, 24)) { ret["Done"] = false; ret["Message"] = "Sorry, voting closed at midnight on 23rd December 2011."; return ret; } MixmagGreatestDj dj = new MixmagGreatestDj(mixmagGreatestDjK); MixmagGreatestVote mgv = new MixmagGreatestVote(); mgv.DateTime = DateTime.Now; mgv.DidWallPost = false; mgv.EmailPermission = true; //mgv.FacebookEmail = email; mgv.FacebookUid = facebook.Uid; mgv.MixmagGreatestDjK = dj.K; mgv.WallPostPermission = true; mgv.FacebookSource = facebookSource == "1"; try { if (!Vars.DevEnv && DateTime.Now > new DateTime(2011, 09, 15, 11, 0, 0)) mgv.Update(); } catch (Exception ex) { MixmagGreatestVoteSet voteSet = new MixmagGreatestVoteSet(new Query(new Q(MixmagGreatestVote.Columns.FacebookUid, facebook.Uid))); if (voteSet.Count > 0) { MixmagGreatestDj votedFor = new MixmagGreatestDj(voteSet[0].MixmagGreatestDjK); ret["Done"] = false; ret["Message"] = "You already voted for " + votedFor.Name + ". Sorry - you can only vote once."; return ret; } else { ret["Done"] = false; ret["Message"] = "There's a problem voting: " + ex.ToString(); return ret; } } try { Update u = new Update(); u.Table = TablesEnum.MixmagGreatestDj; u.Changes.Add(new Assign.Increment(MixmagGreatestDj.Columns.TotalVotes)); u.Where = new Q(MixmagGreatestDj.Columns.K, dj.K); u.Run(); } catch { } //FacebookHttpContext.Current.Status.Set(dj.Name + " is my greatest DJ of all time. Click to vote for yours in the Mixmag poll: http://greatest.dj/"); if (facebookMessage) { try { //send facebook message //http://developers.facebook.com/docs/reference/api/post Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = dj.Image90Url; par["link"] = "http://mixmag-greatest.com/?fb=1"; par["name"] = "Mixmag Greatest Dance Act"; if (dj.IsHidden) { par["description"] = "I voted for my greatest dance act of all time. Vote for yours now in the Mixmag poll..."; } else { par["caption"] = dj.Name; par["description"] = "I voted " + dj.ShortName + " the greatest dance act of all time. Vote for yours now in the Mixmag poll..."; } facebook.PutWallPost("", par); mgv.DidWallPost = true; mgv.Update(); } catch { } } ret["Done"] = true; return ret; } catch (Exception ex) { Hashtable ret = new Hashtable(); ret["Done"] = false; ret["Message"] = ex.ToString(); return ret; } }