public async Task <IActionResult> AddRating(int score, string comment, int bookID)
        {
            //Gets current User.
            var user = await _userManager.GetUserAsync(User);

            var userID = user.Id;

            //Sees if user filled in comment. Avoids null reference error when doing comment.Length.
            if (comment != null)
            {
                //Comment can not exceed 500.
                if (comment.Length > 500)
                {
                    //Returns user to the Rating Site to write again.
                    return(RedirectToAction("Rating", "Book", new { id = bookID }));
                }
            }

            //Creates a new Review model.
            var newReview = new RatingInputModel()
            {
                Score   = score,
                Comment = comment,
                BookID  = bookID,
                UserID  = userID,
            };

            //Adds the rating itself. The comment which is at the bottom of the page.
            _ratingService.AddRating(newReview);
            //Updates the book star rating.
            _bookService.AddRating(newReview);

            //Redirects User to Details.
            return(RedirectToAction("Details", "Book", new { id = bookID }));
        }
Exemplo n.º 2
0
        public IActionResult AddRating(int bookId, int rating)
        {
            //Fall sem tekur við bookId og rating tölu frá notanda, sendir það svo áfram á service
            _bookService.AddRating(bookId, rating);

            return(View());
        }
Exemplo n.º 3
0
        public IActionResult Rate(int?ID, double Rating)
        {
            if (Rating < 0 || Rating > 5)
            {
                return(View("~/Views/Book/RateError.cshtml"));
            }

            else
            {
                _bookService.AddRating(ID, Rating);
                return(View(ID));
            }
        }