Beispiel #1
0
        /// <summary>
        /// лайк картинки
        /// </summary>
        /// <param name="id -id картинки для добавления в лайкнутые"></param>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult LikeImage(int id)
        {
            try
            {
                var  userId = ApplicationUser.GetUserId();
                bool setLike;
                if (userId == null)
                {
                    var    imgsLikedC = HttpContext.Request.Cookies["LikedImgMass"]?.Value ?? "";
                    string newC       = "";

                    Image.AddDelCookies(id.ToString(), imgsLikedC, out newC, out setLike);
                    HttpContext.Response.Cookies["LikedImgMass"].Value = newC;
                    ViewBag.setLike = setLike;
                    return(RedirectToAction("Index"));
                }
                var img = Image.Get(id);
                //if (img == null || img.Deleted)
                //    throw new Exception("картинка не найдена");
                img.Like(out setLike, userId);
                ViewBag.setLike = setLike;
            }
            catch (Exception e)
            {
                Response.StatusCode = 500;
                return(Json(new { errorText = e.Message, inner = e.InnerException?.Message }));
            }


            return(RedirectToAction("Index"));
        }