Beispiel #1
0
		public static void AddEvent(Usr u, Event e, bool attendEvent)
		{

			throw new Exception("Disabled");

			try
			{
				long id = 0;
				if (e.FacebookEventId.HasValue)
				{
					id = e.FacebookEventId.Value;
				}
				else
				{
					#region add event
					FacebookGraphAPI dsiPage = FacebookGraphAPI.GetPageApi(Facebook.Apps.Dsi);

					Dictionary<string, object> ev = new Dictionary<string, object>();
					//access_token, name, description, location, street, city, privacy_type, start_time, end_time, picture
					ev["name"] = e.Name;
					ev["location"] = e.FriendlyNameGeneric(false, true, true, false);
					ev["file.jpg"] = Cropper.TryToGetLargerPic(e, 1.79);
					DateTime d = e.DateTime;
					if (e.StartTime == Model.Entities.Event.StartTimes.Morning)
						d = d.AddHours(6);
					else if (e.StartTime == Model.Entities.Event.StartTimes.Daytime)
						d = d.AddHours(14);
					else if (e.StartTime == Model.Entities.Event.StartTimes.Evening)
						d = d.AddHours(22);
					ev["start_time"] = d.ToString("s");
					ev["end_time"] = d.AddHours(8).ToString("s");
					ev["privacy_type"] = "OPEN";
					ev["no_story"] = "1";


					FacebookPost fp = new FacebookPost();
					fp.Hits = 0;
					fp.FacebookUid = u.Facebook.Uid;
					fp.DateTime = System.DateTime.Now;
					fp.Type = TypeEnum.AddEvent;
					fp.Content = "EventK=" + e.K.ToString();
					fp.DataInt = e.K;
					fp.UsrK = u.K;
					fp.Update();

					Newtonsoft.Json.Linq.JObject post;

					try
					{

						ev["description"] = "Click for full details: http://" + Vars.DomainName + e.UrlShort() + "?fbpk=" + fp.K.ToString();

						//Newtonsoft.Json.Linq.JObject post = u.Facebook.PutObject(u.Facebook.Uid.ToString(), "events", ev);
						post = dsiPage.PutObject(FacebookCommon.Common(Facebook.Apps.Dsi).PageId.ToString(), "events", ev);

					}
					catch
					{
						fp.Delete();
						return;
					}



					try
					{
						id = long.Parse(post["id"].ToString());

					}
					catch { }

					if (id > 0)
					{
						e.FacebookEventId = id;
						e.Update();
					}
					#endregion
				}


				if (attendEvent && id > 0 && u.FacebookConnected && u.FacebookEventAttend)
				{
					try
					{
						u.Facebook.PutObject(id.ToString(), "attending", new Dictionary<string, object>());
					}
					catch { }
				}
			}
			catch
			{
			}
		}
Beispiel #2
0
		public static void CreateAttendEvent(Usr u, Event e)
		{
			Query q = new Query();
			q.QueryCondition = new And(
				new Q(FacebookPost.Columns.DateTime, QueryOperator.GreaterThan, System.DateTime.Now.AddDays(-1)),
				new Q(FacebookPost.Columns.FacebookUid, u.Facebook.Uid),
				new Q(FacebookPost.Columns.Type, TypeEnum.AttendEvent));
			FacebookPostSet fps = new FacebookPostSet(q);
			if (fps.Count < 5)
			{
				Query q1 = new Query();
				q1.QueryCondition = new And(
					new Q(FacebookPost.Columns.FacebookUid, u.Facebook.Uid),
					new Q(FacebookPost.Columns.DataInt, e.K),
					new Or(new Q(FacebookPost.Columns.Type, TypeEnum.BuyTicket), new Q(FacebookPost.Columns.Type, TypeEnum.AttendEvent)));
				FacebookPostSet fps1 = new FacebookPostSet(q1);
				if (fps1.Count == 0)
				{

					FacebookPost fp = new FacebookPost();
					fp.Hits = 0;
					fp.FacebookUid = u.Facebook.Uid;
					fp.DateTime = System.DateTime.Now;
					fp.Type = TypeEnum.AttendEvent;
					fp.Content = "EventK=" + e.K.ToString();
					fp.DataInt = e.K;
					fp.UsrK = u.K;
					fp.Update();

					//send facebook message
					//http://developers.facebook.com/docs/reference/api/post
					Dictionary<string, object> par = new Dictionary<string, object>();
					par["picture"] = e.HasAnyPic ? e.AnyPicPath : "http://www.dontstayin.com/gfx/logo-90.png";
					par["link"] = "http://" + Vars.DomainName + e.Url() + "?fbpk=" + fp.K.ToString();
					par["name"] = e.FriendlyNameGeneric(true, false, false, false);
					par["caption"] = "Don't Stay In";
					par["description"] = ("@ " + e.FriendlyNameGeneric(false, true, true, true) + " - " + e.ShortDetailsHtml).TruncateWithDots(990);
					u.Facebook.PutWallPost(e.IsFuture ? "I'm going to this..." : "I went to this...", par);
				}
			}
		}