public ActionResult Filter(Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         var _results = context.Fans.Select(a => a);
         if (Fan.FirstName != null)
         {
             _results = _results.Where(a => a.FirstName.Contains(Fan.FirstName));
         }
         if (Fan.LastName != null)
         {
             _results = _results.Where(a => a.LastName.Contains(Fan.LastName));
         }
         if (Fan.Gender != "All")
         {
             _results = _results.Where(a => a.Gender == Fan.Gender);
         }
         if (Fan.YearsInClub != 0)
         {
             _results = _results.Where(a => a.YearsInClub == Fan.YearsInClub);
         }
         return(CheckLoggedIn("Fans/FanList", _results.ToList()));
         // return View("Fans/FanList", _results.ToList());
     }
 }
        public ActionResult Map()
        {
            using (var context = new ShauliBlogContext())
            {
                var _fans         = context.Fans.ToList();
                var _grouped_fans = context.Fans.GroupBy(a => new { a.FanLocation.Country, a.FanLocation.City })
                                    .ToList();
                var _dict = new Dictionary <string, List <Fan> >();

                foreach (var item in _grouped_fans)
                {
                    var _list = new List <Fan>();
                    _list.AddRange(item.ToList());

                    _dict.Add(item.Key.Country + ", " + item.Key.City, _list);
                }

                var _json_arr = new JArray();
                foreach (var fan in _fans)
                {
                    var _obj = new JObject();
                    _obj.Add("FanName", fan.FirstName + " " + fan.LastName);
                    _obj.Add("PlaceId", fan.FanLocation.PlaceId);
                    _json_arr.Add(_obj);
                }

                var _tuple = new Tuple <string, Dictionary <string, List <Fan> > >(_json_arr.ToString(Newtonsoft.Json.Formatting.None),
                                                                                   _dict);
                return(CheckLoggedIn("Fans/Map", _tuple));
                //return View("Fans/Map", _tuple);
            }
        }
Example #3
0
        public ActionResult Filter(FilterParams FilterParams)
        {
            //filtering blog entrees by the field below:
            using (var context = new ShauliBlogContext())
            {
                var _results = context.Posts.Select(a => a);
                if (FilterParams.DateFrom != null)
                {
                    _results = _results.Where(a => a.PostDate >= FilterParams.DateFrom && a.PostDate <= FilterParams.DateTo);
                }
                if (FilterParams.Author != null)
                {
                    _results = _results.Where(a => a.Author.Contains(FilterParams.Author));
                }
                if (FilterParams.Content != null)
                {
                    _results = _results.Where(a => a.PostContent.Contains(FilterParams.Content));
                }
                if (FilterParams.CommentContent != null)
                {
                    _results = _results.Where(a => a.Comments
                                              .Any(b => b.CommentContent.Contains(FilterParams.CommentContent)))
                               .Include(a => a.Comments);
                }

                return(View("Blog", _results.Include(a => a.Comments).ToList()));
            }
        }
 public ActionResult AddNewPost(Post Post)
 {
     using (var context = new ShauliBlogContext())
     {
         context.Posts.Add(Post);
         context.SaveChanges();
         return(RedirectToAction("ManagePosts"));
     }
 }
 public ActionResult Create(Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         context.Fans.Add(Fan);
         context.SaveChanges();
         return(RedirectToAction("ThankYou"));
     }
 }
Example #6
0
        //
        // GET: /Blog/

        public ActionResult Index()
        {
            using (var context = new ShauliBlogContext())
            {
                //including comments list (Join in sql) in the post object
                var _posts = context.Posts.Include(a => a.Comments).ToList();
                return(View("Blog", _posts.OrderByDescending(a => a.PostDate).ToList()));
            }
        }
 public ActionResult EditPost(int Id)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.SingleOrDefault(a => a.PostId == Id);
         return(CheckLoggedIn("Blog/Posts/EditPost", _post));
         //  return View("Blog/Posts/EditPost", _post);
     }
 }
 public ActionResult ShowComments(int Id)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.Include(a => a.Comments).SingleOrDefault(a => a.PostId == Id);
         return(CheckLoggedIn("Blog/Posts/DisplayComments", _post));
         //   return View("Blog/Posts/DisplayComments", _post);
     }
 }
 public ActionResult Delete(int Id, Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         var _fan = context.Fans.Where(a => a.Id == Id).SingleOrDefault();
         context.Fans.Remove(_fan);
         context.SaveChanges();
         return(RedirectToAction("FansList"));
     }
 }
Example #10
0
 public ActionResult AddNewComment(int Id, Comment Comment)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.Where(a => a.PostId == Id).SingleOrDefault();
         // Comment.Post = _post;
         _post.Comments.Add(Comment);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult DeleteComment(int PostId, int CommentId)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post    = context.Posts.SingleOrDefault(a => (a.PostId == PostId));
         var _comment = _post.Comments.SingleOrDefault(a => a.CommentId == CommentId);
         _post.Comments.Remove(_comment);
         context.SaveChanges();
         return(RedirectToAction(String.Format("Blog/Posts/{0}/comments", PostId)));
     }
 }
        public ActionResult ManagePosts()
        {
            using (var context = new ShauliBlogContext())
            {
                return(CheckLoggedIn("Blog/Posts", context.Posts.OrderByDescending(a => a.PostDate)
                                     .Include(b => b.Comments)
                                     .ToList()));

                //return View("Blog/Posts", context.Posts.OrderByDescending(a => a.PostDate)
                //    .Include(b => b.Comments)
                //    .ToList());
            }
        }
 public ActionResult Delete(int Id)
 {
     using (var context = new ShauliBlogContext())
     {
         var _fan = context.Fans.Where(a => a.Id == Id).SingleOrDefault();
         if (_fan == null)
         {
             return(HttpNotFound("Id does not exist"));
         }
         return(CheckLoggedIn("Fans/DeleteFan", _fan));
         // return View("Fans/DeleteFan", _fan);
     }
 }
 public ActionResult Update(int Id, Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         var _fan = context.Fans.Where(a => a.Id == Id).SingleOrDefault();
         _fan.FirstName   = Fan.FirstName;
         _fan.LastName    = Fan.LastName;
         _fan.Birthday    = Fan.Birthday;
         _fan.Gender      = Fan.Gender;
         _fan.YearsInClub = Fan.YearsInClub;
         _fan.FanLocation = Fan.FanLocation;
         context.SaveChanges();
         return(RedirectToAction("FansList"));
     }
 }
        public ActionResult DeletePost(int Id, Post Post)
        {
            using (var context = new ShauliBlogContext())
            {
                var _post = context.Posts.SingleOrDefault(a => a.PostId == Id);

                //first remove comments of the selected post
                _post.Comments.RemoveRange(0, _post.Comments.Count);

                //then remove post it self
                context.Posts.Remove(_post);
                context.SaveChanges();
                return(RedirectToAction("ManagePosts"));
            }
        }
 public ActionResult EditPost(int Id, Post Post)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.SingleOrDefault(a => a.PostId == Id);
         _post.ImageUrl          = Post.ImageUrl;
         _post.VideoUrl          = Post.VideoUrl;
         _post.Author            = Post.Author;
         _post.AuthorSiteAddress = Post.AuthorSiteAddress;
         _post.PostContent       = Post.PostContent;
         _post.PostTitle         = Post.PostTitle;
         context.SaveChanges();
         return(RedirectToAction("ManagePosts"));
     }
 }
        public ActionResult FansList()
        {
            try
            {
                using (var context = new ShauliBlogContext())
                {
                    List <Fan> _list = context.Fans.ToList();
                    return(CheckLoggedIn("Fans/FanList", _list));
                    //  return View("Fans/FanList", _list);
                }
            }
            catch (Exception e)
            {
                throw;
            }


            // return View("FanList", GenerateDummyFans());
        }