Exemplo n.º 1
0
        public ActionResult Activity()
        {
            List <String> addresses           = new List <String>();
            List <String> blogNames           = new List <String>();
            List <String> ids                 = new List <String>();
            List <String> mostRecentPostDates = new List <String>();

            using (personContext)
            {
                addresses = (from blogger in personContext.Persons
                             select blogger.location).ToList();

                blogNames = (from blogger in personContext.Persons
                             select blogger.blogName).ToList();

                ids = (from blogger in personContext.Persons
                       select blogger.Id.ToString()).ToList();

                foreach (String id in ids)
                {
                    int id_number = int.Parse(id);
                    ICollection <BlogPost> blogPosts = (from person in personContext.Persons
                                                        where person.Id == id_number
                                                        select person.posts).FirstOrDefault();

                    if (blogPosts.Count == 0)
                    {
                        // special case where a newly registered user hasn't made any posts just yet
                        mostRecentPostDates.Add("No posts yet");
                    }
                    else
                    {
                        blogPosts.OrderBy(x => x.dateCreated);
                        mostRecentPostDates.Add(blogPosts.ElementAt(0).dateCreated.ToString());
                    }
                }
            }

            var jsonMaker = new JavaScriptSerializer();

            ViewBag.geocodes = jsonMaker.Serialize(ActivityViewLogic.retrieveGeoPoints(addresses, blogNames, ids, mostRecentPostDates));

            ViewBag.blogNames = jsonMaker.Serialize(blogNames);
            ViewBag.ids       = jsonMaker.Serialize(ids);
            ViewBag.postDates = jsonMaker.Serialize(mostRecentPostDates);

            return(View());
        }
Exemplo n.º 2
0
        public string GetTagComparison()
        {
            var jsonMaker = new JavaScriptSerializer();
            Dictionary <string, List <string> > tagRanks = new Dictionary <string, List <string> >();

            tagRanks = ActivityViewLogic.getTopTags();

            if (tagRanks == null)
            {
                // something went wrong, return an error status code and do not return any data
                Response.StatusCode = 400;
                return("");
            }
            else
            {
                return(jsonMaker.Serialize(tagRanks));
            }
        }
Exemplo n.º 3
0
        public string GetTopBloggers()
        {
            var jsonMaker = new JavaScriptSerializer();

            Dictionary <string, List <string> > bloggerRanks = new Dictionary <string, List <string> >();

            bloggerRanks = ActivityViewLogic.getTopBloggers();

            if (bloggerRanks == null)
            {
                // something went wrong, return an error code and do not send any data back
                Response.StatusCode = 400;
                return("");
            }
            else
            {
                return(jsonMaker.Serialize(bloggerRanks));
            }
        }
Exemplo n.º 4
0
        public ActionResult Index()
        {
            //CreateTags.generate(personContext);

            List <String> trends = ActivityViewLogic.getTrends();

            ViewBag.trends = trends;
            //if user is logged in see public and followings posts
            if (Request.IsAuthenticated)
            {
                Person currUser = GeneralLogic.getLoggedInUser(personContext);
                List <KeyValuePair <int, string> > recommendations = new List <KeyValuePair <int, string> >();
                GeneralLogic.getRecommendedPeopleFor(personContext, currUser).ForEach(person => recommendations.Add(new KeyValuePair <int, string>(person.Id, person.FirstName + " " + person.LastName)));
                ViewBag.recommendations = recommendations;
                List <BlogPost> blogPosts = new List <BlogPost>();
                List <BlogPost> blogList  = personContext.BlogPosts.OrderByDescending(blog => blog.dateCreated).ToList();
                foreach (BlogPost p in blogList)
                {
                    if (p.person.followers.Contains(currUser) || !p.person.isPrivate)
                    {
                        blogPosts.Add(p);
                    }
                }
                return(View(blogPosts));
            }
            else
            {
                //if user is not logged in, only see public posts
                List <BlogPost> blogPosts = new List <BlogPost>();
                foreach (BlogPost p in personContext.BlogPosts)
                {
                    if (!p.person.isPrivate)
                    {
                        blogPosts.Add(p);
                    }
                }
                return(View(blogPosts));
            }
        }