public async Task<ActionResult> PlacesData(
            long? participantId = null,
            long? eventTypeId = null)
        {
            if (!participantId.HasValue)
            {
                participantId = NietzscheConstants.NietzscheId;
            }

            var locations = from l in this.locationRepository
                            where l.EventInvolvements.Any(li =>
                                li.Event.ParticipantInvolvements.Any(pi =>
                                    pi.ParticipantId == participantId)
                                && (eventTypeId.HasValue ? li.Event.TypeId == eventTypeId.Value : true))
                            let c = l as Country
                            let pp = l as PopulatedPlace
                            let a = l as Address
                            select new LocationDto
                            {
                                location_id = l.Id,
                               
                                title = c != null ? c.Name
                                      : pp != null ? pp.Name 
                                          + (pp.Country != null ? ", " + pp.Country.Name : "")
                                      : a != null ? a.StreetName
                                          + (a.BuildingNumber != null ? " " + a.BuildingNumber + ", " : ", ")
                                          + a.PopulatedPlace.Name
                                          + (a.PopulatedPlace.Country != null ? ", " + a.PopulatedPlace.Country.Name : "")
                                      : "",
                               
                                latitude = l.GeoLocation.Latitude,
                               
                                longitude = l.GeoLocation.Longitude,
                               
                                events = from li in l.EventInvolvements
                                         let e = li.Event
                                         where e.ParticipantInvolvements.Any(pi => pi.ParticipantId == participantId)
                                             && (eventTypeId.HasValue ? e.TypeId == eventTypeId.Value : true)
                                         //group e by e.Id into events
                                         //let e = events.First()
                                         select new EventDto
                                         {
                                             event_id = e.Id,
                                             event_type = e.Type.Label,
                                             event_type_id = e.Type.Id
                                         }
                            };

            var locations2 = await locations.ToListAsync();

            var eventTypeOccurences = from l in locations2
                                      from e in l.events
                                      group e by e.event_type_id into typeGroup
                                      let occurenceCount = typeGroup.Count()
                                      orderby occurenceCount descending
                                      select new
                                      {
                                          Label = typeGroup.First().event_type,
                                          Count = occurenceCount
                                      };

            foreach (var l in locations2)
            {
                l.title = HttpUtility.HtmlEncode(l.title);
            }
            
            var data = new
            {
                locations = locations2,
                event_type_occurrences = eventTypeOccurences.ToDictionary(g => g.Label, g => g.Count)
            };

            return this.Json(data, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
        public async Task<JsonResult> SendComment(PhotoStatusChangeModel model)
        {
            try
            {
                using (var db = new MySelfieEntities())
                {
                    var photo = db.Photos.Single(x => x.PhotoId == model.PhotoTweetId);

                    var wall = photo.Wall;

                    string token = wall.PostingAccount_InstagramPassword;
                    string id = photo.SocialIDstring;
                    string template = wall.RetweetMessage;
                    string username = photo.Username;

                    //I should not have put all of this should not be in the controller, but the comment sending was really
                    //Couple to the batch creation
                    string response = "";
                    var success = true;


                    if (photo.Source == "Twitter")
                    {
                        var context = PhotoStatusChangeModel.GetTwitterContext(new PhotoStatusChangeModel.WallModel(wall));
                        response = await PhotoStatusChangeModel.PublishTweet(photo.Username, DateTime.UtcNow, wall.RetweetMessage, context);
                    }
                    if (photo.Source == "Instagram")
                    {
                        response = PhotoStatusChangeModel.PublishInstagramComment(photo.Username, DateTime.UtcNow, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring);
                    }
                    if (response == "")
                    {
                        photo.Status = "commentSent";
                    }
                    else 
                    {
                        success = false;
                    }
                    db.SaveChanges();

                    var stuff = new { success = success, response = response };
                    return (Json(stuff));
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Photo/Status");

                return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet);
            }
        }