예제 #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
			{
			}
		}