Ejemplo n.º 1
0
        public IActionResult Like(int id)
        {
            String username = HttpContext.Session.GetString("Username");

            if (username != null)
            {
                var like = _like.GetLike(username, id);
                if (like == null)
                {
                    like           = new Like();
                    like.ProductId = id;
                    like.UserId    = username;
                    like.product   = _product.GetById(id);
                    _like.AddLike(like);

                    return(Json(new { success = true, msg = "You have liked " + like.product.Name }));
                    // HttpContext.Session.Remove("ERRORLIKE");
                }
                else
                {
                    return(Json(new { success = true, msg = "You have liked this game" }));
                    // ViewBag.ERROR = "YOU HAVE LIKED THIS GAME!!!";
                }
            }
            else
            {
                return(Json(new { success = true, msg = "You must login before liking this game" }));
                // return RedirectToAction("Login", "Home");
            }

            return(RedirectToAction("List"));
        }
Ejemplo n.º 2
0
 public async Task <Like> GetLike(Guid id)
 {
     return(await _likeRepository.GetLike(id));
 }