Esempio n. 1
0
        public IActionResult Like(int PostId)
        {
            int?userID = HttpContext.Session.GetInt32("UserID");

            if (userID == null)
            {
                return(View("index"));
            }
            var check = _context.likers.SingleOrDefault(c => c.PostId == PostId && c.UsersId == userID);

            if (check != null)
            {
                return(RedirectToAction("DashBoard"));
            }
            var like = _context.post.SingleOrDefault(l => l.PostId == PostId);

            if (like.UsersId == userID)
            {
                return(RedirectToAction("DashBoard"));
            }
            Likers newLiker = new Likers();

            newLiker.UsersId = (int)userID;
            newLiker.PostId  = PostId;
            like.Likes++;
            _context.Add(newLiker);
            _context.SaveChanges();
            return(RedirectToAction("DashBoard"));
        }
Esempio n. 2
0
            public static Likers FromElement(XElement e)
            {
                var cs = new Likers
                {
                    on_this_page = int.Parse(e.Attribute("on_this_page").Value),
                    page         = int.Parse(e.Attribute("page").Value),
                    perpage      = int.Parse(e.Attribute("perpage").Value),
                    total        = int.Parse(e.Attribute("total").Value)
                };

                cs.AddRange(e.Elements("user").Select(Liker.FromElement));
                return(cs);
            }