Пример #1
0
        public IActionResult New(int ArtID, double rate)
        {
            Rate r = new Rate()
            {
                Vote = rate, ArtID = ArtID
            };

            ViewBag.ValueRate = RateService.GetVote(ArtID);
            r.UserID          = User.FindFirstValue(ClaimTypes.NameIdentifier);
            ViewBag.UserRate  = RateService.GetVoteByUser(r.UserID, ArtID);


            try
            {
                ViewBag.ArtId = ArtID;
                RateService.Add(r);
                ViewBag.ValueRate = RateService.GetVote(ArtID);
                ViewBag.UserRate  = RateService.GetVoteByUser(r.UserID, ArtID);
                return(Content(Math.Round(ViewBag.ValueRate, 2) + " / 5"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(Content("Error " + ex.Message));
            }
        }
        public IViewComponentResult Invoke(int id)
        {
            ViewBag.ValueRate = Math.Round(rateService.GetVote(id), 2);
            var UserID = manager.GetUserId(HttpContext.User);

            ViewBag.ArtId    = id;
            ViewBag.UserRate = rateService.GetVoteByUser(UserID, id);
            return(View("_RatePartialView"));
        }