Пример #1
0
        /*    public ViewBookViewModel AddReview(string bookId)
         *  {
         *      throw new NotImplementedException();
         *  }
         */
        public ViewBookViewModel PreparedPage(string bookId)
        {
            var book  = this.context.Books.FirstOrDefault(b => b.Id == bookId);
            var genre = this.context.Genres.FirstOrDefault(g => g.Id == book.GenreId);
            var user  = this.context.Users.FirstOrDefault(u => u.Id == book.UserId);
            var reviewsOfBookViewModel = this.context.BookReviews
                                         .Where(r => r.BookId == book.Id)
                                         .OrderBy(r => r.CreatedOn)
                                         .Select(r => new ReviewsOfBookViewModel()
            {
                Text = r.Review,
            }).ToList();
            ViewBookViewModel model = new ViewBookViewModel()
            {
                Author                  = book.Author,
                BookId                  = book.Id,
                CatalogNumber           = book.CatalogNumber,
                GenreId                 = book.GenreId,
                GenreName               = genre.Name,
                Logo                    = book.Logo,
                Review                  = book.Review,
                Title                   = book.Title,
                UserEmailName           = user.Email,
                UserFirstName           = user.FirstName,
                UserLastName            = user.LastName,
                ReviewsOfBookViewModels = reviewsOfBookViewModel,
                //Reveiews = reviews,
            };

            return(model);
        }
        public IActionResult AddReview(ViewBookViewModel model)
        {
            this.StartUp();
            var bookId      = this.TempData["viewBookId"].ToString();
            var result      = this.viewBookService.AddReview(model, bookId, this.userId);
            var returnModel = result["model"];

            this.ViewData["messageAddReview"] = result["message"];
            this.TempData["viewBookId"]       = bookId;
            return(this.View("ViewBook", returnModel));
        }
Пример #3
0
        public Dictionary <string, object> AddReview(ViewBookViewModel model, string bookId, string userId)
        {
            var book = this.context.Books.FirstOrDefault(b => b.Id == bookId);
            var user = this.context.Users.FirstOrDefault(u => u.Id == userId);

            BookReview newBookReview = new BookReview()
            {
                Review = model.NewReveiew,
                BookId = bookId,
                UserId = userId,
            };

            this.context.BookReviews.Add(newBookReview);
            this.context.SaveChanges();
            Dictionary <string, object> result = new Dictionary <string, object>();
            var message = $"Успешно дадено мнение за книгата {book.Title}, написана от {book.Author}";

            ///this.notificationService.AddNotificationAtDB(message, userId);
            result.Add("message", message);
            result.Add("model", this.PreparedPage(bookId));
            return(result);
        }