public PartialViewResult SetRating(Rating rating) { Rating existed = context.Ratings.FirstOrDefault(r => r.BookId == rating.BookId && r.UserId == rating.UserId); if (existed == null) { context.Ratings.Add(rating); } else { existed.Value = rating.Value; } context.SaveChanges(); HomeIndexViewModel viewModel = new HomeIndexViewModel { Books = context.Books.ToList(), Recommendations = CollaborativeFilter.GetRecomendations(context, User.Identity.GetUserId()), Genres = context.Genres.ToList(), Countries = context.Countries.ToList(), FilterModel = FilterModel ?? new FilterModel() }; return(PartialView("BooksRecomendationsPartial", viewModel)); }
public ActionResult Books() { HomeIndexViewModel viewModel = new HomeIndexViewModel { Books = context.Books.ToList(), Recommendations = CollaborativeFilter.GetRecomendations(context, User.Identity.GetUserId()), Genres = context.Genres.ToList(), Countries = context.Countries.ToList(), FilterModel = FilterModel ?? new FilterModel() }; return(View(viewModel)); }
public PartialViewResult RemoveRating(int id) { Rating rating = context.Ratings.First(r => r.Id == id); context.Ratings.Remove(rating); context.SaveChanges(); HomeIndexViewModel viewModel = new HomeIndexViewModel { Books = context.Books.ToList(), Recommendations = CollaborativeFilter.GetRecomendations(context, User.Identity.GetUserId()), Genres = context.Genres.ToList(), Countries = context.Countries.ToList(), FilterModel = FilterModel ?? new FilterModel() }; return(PartialView("BooksRecomendationsPartial", viewModel)); }