// A location bubble was popped. Notify the server and display the notification string to the user. async void Pop(object sender, CLRegionEventArgs e) { if (!e.Region.Identifier.Equals("RefreshZone")) // Ignore the refresh zone. { // Get the ID of the bubble that was popped. int bubbleId = Int32.Parse(e.Region.Identifier); Debug.WriteLine(">>>>> Popped bubble #" + bubbleId.ToString()); // Notify the server and get notification message. EventMobile localEvent = new EventMobile(); localEvent.BubbleId = bubbleId; localEvent.TimestampJson = DateTime.Now.ToLongTimeString(); string json = await WebApiPost("api/Event", localEvent); EventMobile serverEvent = (EventMobile)JsonConvert.DeserializeObject(json, typeof(EventMobile)); // If the event has not been suppressed, process it. if (!serverEvent.Suppressed) { Debug.WriteLine(">>>>> Processing event: Bubble #" + bubbleId.ToString()); // Display a notification. DisplayNotification(serverEvent.ProviderName, serverEvent.MsgTitle, serverEvent.Msg, "Popdit" + " " + e.Region.Identifier); // If the pops page is displayed, refresh it. UIWebView webView = (UIWebView)UIApplication.SharedApplication.KeyWindow.RootViewController.View; if (webView.Request.Url.AbsoluteString.Contains("Event")) { webView.LoadRequest(new NSUrlRequest(PopditServer.WebRoot)); } } else { Debug.WriteLine(">>>>> Event suppressed: Bubble #" + bubbleId.ToString()); } } }
Event FromInterop(EventMobile em) { Event e = new Event(); e.BubbleId = em.BubbleId; e.Id = em.Id; e.ProfileId = em.ProfileId; e.Timestamp = em.Timestamp; return(e); }
EventMobile ToInterop(Event e, Bubble b) { EventMobile em = new EventMobile(); em.Id = e.Id; em.ProviderName = b.Profile.Nickname; em.MsgTitle = b.Name; em.Msg = b.AlertMsg; em.Timestamp = e.Timestamp; return(em); }
public IHttpActionResult PostEvent(EventMobile em) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Get user. int userId = AuthenticatedUserId; Profile user = db.Profiles.Find(userId); // Get bubble and its creator. Bubble bubble = db.Bubbles.Find(em.BubbleId); //db.Entry(bubble).Reference(b => b.Profile).Load(); // TBD - speed this up - this is crap. // Don't pop anything that's been popped in the last 24 hours. DateTime dayAgo = DateTime.Now.AddDays(-1); if (bubble.IsFriendly(user) && bubble.IsFresh(user, dayAgo)) { // Save the event in the DB. em.ProfileId = userId; // Security. Event evnt = FromInterop(em); db.Events.Add(evnt); db.SaveChanges(); // Set EventMobileFields for return trip. em = ToInterop(evnt, bubble); em.Suppressed = false; // TBD - enable suppression. } else { em.Suppressed = true; } return(CreatedAtRoute("DefaultApi", new { id = em.Id }, em)); }