protected void Page_Load(object sender, EventArgs e) { Query q = new Query(); q.QueryCondition = new Q(MixmagEntry.Columns.MixmagCompK, int.Parse(Url["CompK"])); q.OrderBy = new OrderBy(MixmagEntry.Columns.DateTime, OrderBy.OrderDirection.Descending); q.ExtraSelectElements.Add("Votes", "(SELECT COUNT(*) FROM [MixmagVote] WHERE [MixmagVote].[MixmagEntryK]=[MixmagEntry].[K])"); MixmagEntrySet mes = new MixmagEntrySet(q); StringBuilder s = new StringBuilder(); foreach (MixmagEntry me in mes) { s.Append("<div style='width:30px; float:left;'>" + me.ExtraSelectElements["Votes"].ToString() + "</div>"); s.Append("<div style='float:left;'><a href='" + me.ImageUrl + "' target='_blank'>" + me.ImageUrl + "</a></div><br />"); } Output.Controls.Add(new LiteralControl(s.ToString())); }
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 SaveQuestion(int entryK, int compK, string imageUrl, string questionString) { 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 { ret["Done"] = false; ret["Message"] = "Can't find this entry."; return ret; } } 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) { ret["Done"] = false; ret["Message"] = "Vote not found."; return ret; } Query q = new Query( new And( new Q(Bobs.MixmagVote.Columns.MixmagEntryK, e.K), new Q(Bobs.MixmagVote.Columns.FacebookUID, facebook.Uid) ) ); MixmagVoteSet mvs = new MixmagVoteSet(q); if (mvs.Count == 0) { ret["Done"] = false; ret["Message"] = "Vote not found."; return ret; } Bobs.MixmagVote v = mvs[0]; v.TextField1 = questionString; v.Update(); ret["Done"] = true; ret["MixmagVoteK"] = v.K; return ret; }
public static void SendUpdateEmails() { //send updates MixmagComp c1 = MixmagComp.GetByK(2); if (c1.EndDate < System.DateTime.Now) return; List<string> emails = new List<string>(); Query qEmails = new Query(); qEmails.QueryCondition = new And( new Q(MixmagEntry.Columns.DateTime, QueryOperator.GreaterThan, System.DateTime.Now.AddDays(-28)), new Q(MixmagEntry.Columns.SendDailyEmails, true)); MixmagEntrySet mesEmails = new MixmagEntrySet(qEmails); foreach (MixmagEntry meEmail in mesEmails) { if (emails.Contains(meEmail.Email)) continue; emails.Add(meEmail.Email); Query qComps = new Query(); qComps.QueryCondition = new And( new Q(MixmagEntry.Columns.DateTime, QueryOperator.GreaterThan, System.DateTime.Now.AddDays(-28)), new Q(MixmagEntry.Columns.SendDailyEmails, true), new Q(MixmagEntry.Columns.Email, meEmail.Email)); qComps.OrderBy = new OrderBy(MixmagEntry.Columns.K); MixmagEntrySet mesComps = new MixmagEntrySet(qComps); //string s = ""; if (mesComps.Count > 0) { List<int> comps = new List<int>(); foreach (MixmagEntry meComp in mesComps) { if (comps.Contains(meComp.MixmagCompK)) continue; comps.Add(meComp.MixmagCompK); MixmagComp comp = MixmagComp.GetByK(meComp.MixmagCompK); Query qEntries = new Query(); qEntries.QueryCondition = new And( new Q(MixmagEntry.Columns.DateTime, QueryOperator.GreaterThan, System.DateTime.Now.AddDays(-28)), new Q(MixmagEntry.Columns.SendDailyEmails, true), new Q(MixmagEntry.Columns.Email, meComp.Email), new Q(MixmagEntry.Columns.MixmagCompK, meComp.MixmagCompK)); qEntries.OrderBy = new OrderBy(MixmagEntry.Columns.K); MixmagEntrySet mesEntries = new MixmagEntrySet(qEntries); if (mesEntries.Count > 0) { string s = comp.DailyEmailHtmlComp; int entryNumber = 1; foreach (MixmagEntry meEntry in mesEntries) { if (mesEntries.Count > 1) s += comp.DailyEmailHtmlEntryMultiple.Replace("%1", entryNumber.ToString()); entryNumber++; Query qVoteCount = new Query(); qVoteCount.QueryCondition = new Q(MixmagVote.Columns.MixmagEntryK, meComp.K); qVoteCount.ReturnCountOnly = true; MixmagVoteSet mvsVoteCount = new MixmagVoteSet(qVoteCount); int daysToGo = (int)(meEntry.DateTime.Value.AddDays(30) - System.DateTime.Now).TotalDays; if (daysToGo < 1) daysToGo = 1; s += comp.DailyEmailHtmlEntry .Replace("%1", meEntry.ImageUrl) .Replace("%2", mvsVoteCount.Count.ToString("#,##0")) .Replace("%3", mvsVoteCount.Count == 1 ? "" : "s") .Replace("%4", daysToGo.ToString("#,##0")) .Replace("%5", daysToGo == 1 ? "" : "s") .Replace("%6", "http://mixmag-vote.com/repost?entry=" + meEntry.K.ToString()) .Replace("%7", "http://mixmag-vote.com/" + meEntry.K.ToString()); } s += @" <p> To stop these daily emails, <a href=""http://mixmag-vote.com/stop?email=" + HttpUtility.UrlEncode(meEmail.Email) + @""">click here</a>. </p> "; System.Net.Mail.SmtpClient c = new System.Net.Mail.SmtpClient(); c.Host = Common.Properties.GetDefaultSmtpServer(); System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(); string fullBody = s; m.Body = fullBody.Replace("\n", "\n\r"); m.From = new System.Net.Mail.MailAddress("*****@*****.**"); m.IsBodyHtml = true; m.Subject = comp.DailyEmailHtmlCompSubject; if (Vars.DevEnv) { m.To.Add("*****@*****.**"); } else { m.To.Add(meEmail.Email); } c.Send(m); } } } } }