public static Hashtable RepostNow(int entryK, string message) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagVote); JObject user = facebook.GetObject("me", null); MixmagEntry me = new MixmagEntry(entryK); MixmagComp c = MixmagComp.GetByK(me.MixmagCompK); Hashtable ret = new Hashtable(); try { Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = me.ImageUrl; par["link"] = "http://mixmag-vote.com/" + me.K; par["name"] = c.FacebookPostName; par["caption"] = c.FacebookPostCaption; par["description"] = c.FacebookPostDescription; facebook.PutWallPost(message, par); } catch { ret["Done"] = false; return ret; } ret["Done"] = true; return ret; }
public static Hashtable VoteNow(int entryK, int compK, string imageUrl) { var facebook = new FacebookGraphAPI(Facebook.Apps.MixmagVote); 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"); MixmagComp c = null; MixmagEntry e = null; if (entryK > 0) { try { e = new MixmagEntry(entryK); } catch { } } Hashtable ret = new Hashtable(); if (e != null) { //got an entry c = MixmagComp.GetByK(e.MixmagCompK); } else if (imageUrl.Length > 0 && compK > 0) { c = MixmagComp.GetByK(compK); MixmagEntrySet mes = new MixmagEntrySet(new Query(new And(new Q(MixmagEntry.Columns.MixmagCompK, compK), new Q(MixmagEntry.Columns.ImageUrl, imageUrl)))); if (mes.Count > 0) { e = mes[0]; } else { //create a new skeleton entry for this image e = new MixmagEntry(); e.DateTime = DateTime.Now; e.Email = ""; e.FacebookUid = 0; e.FirstName = ""; e.LastName = ""; e.ImageUrl = imageUrl; e.MixmagCompK = c.K; e.Update(); } } else { ret["Done"] = false; ret["Message"] = "Can't find this entry."; return ret; } if (!c.Enabled) { ret["Done"] = false; ret["Message"] = "This competition isn't enabled."; return ret; } if (DateTime.Now > c.EndDate) { ret["Done"] = false; ret["Message"] = "This competition is now closed."; return ret; } if (DateTime.Now < c.StartDate) { ret["Done"] = false; ret["Message"] = "This competition hasn't started yet."; return ret; } if (e.K > 0) { Query q = new Query( new And( new Q(Bobs.MixmagVote.Columns.MixmagEntryK, e.K), new Q(Bobs.MixmagVote.Columns.FacebookUID, facebook.Uid) ) ); q.ReturnCountOnly = true; MixmagVoteSet mes = new MixmagVoteSet(q); if (mes.Count > 0) { ret["Done"] = false; ret["Message"] = "You have already voted for this photo."; return ret; } } Bobs.MixmagVote v = new Bobs.MixmagVote(); v.DateTime = DateTime.Now; v.FacebookUID = facebook.Uid; v.MixmagEntryK = e.K; v.Update(); if (e.FacebookUid.HasValue && e.FacebookUid.Value > 0 && c.FacebookVoteMessage.Length > 0) { try { Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = e.ImageUrl; par["link"] = "http://mixmag-vote.com/" + e.K; par["name"] = c.FacebookPostName; par["caption"] = c.FacebookPostCaption; par["description"] = c.FacebookPostDescription; facebook.PutWallPost(c.FacebookVoteMessage, par); } catch { } } ret["Done"] = true; ret["MixmagVoteK"] = v.K; return ret; }
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; } }
public static void CreateNewConnect(FacebookGraphAPI facebook, int usrK) { Query q = new Query(); q.QueryCondition = new And( new Q(FacebookPost.Columns.FacebookUid, facebook.Uid), new Q(FacebookPost.Columns.Type, TypeEnum.NewConnect)); FacebookPostSet fps = new FacebookPostSet(q); if (fps.Count == 0) { FacebookPost fp = new FacebookPost(); fp.Hits = 0; fp.FacebookUid = facebook.Uid; fp.DateTime = System.DateTime.Now; fp.Type = TypeEnum.NewConnect; fp.Content = ""; fp.UsrK = usrK; fp.Update(); //send facebook message //http://developers.facebook.com/docs/reference/api/post Dictionary<string, object> par = new Dictionary<string, object>(); par["picture"] = Vars.DevEnv ? "http://pix-cdn.dontstayin.com/db864428-71be-4216-9d06-d641ce992301.png" : "http://www.dontstayin.com/gfx/logo-90.png"; par["link"] = "http://www.dontstayin.com/?fbpk=" + fp.K.ToString(); par["name"] = "Don't Stay In"; facebook.PutWallPost("I've just connected to Don't Stay In...", par); } }