예제 #1
0
        // GET: /Movies/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Movie movie = db.Movies.Include("Votes").Include("Votes.User").FirstOrDefault(x => x.Id == id);

            var model = new MovieFullDetails
            {
                Id = movie.Id,
                Title = movie.Title,
                Director = movie.Director,
                Year = movie.Year,
                Actors = movie.Actors,
                Duration = movie.Duration,
                Trailer = movie.Trailer,
                Poster = movie.Poster,
                Description = movie.Description,
                Country = movie.Country,
                Category = movie.Category,
                ParentsGuide = movie.ParentsGuide,
                Votes = movie.Votes,
                Comments = movie.Comments.Select(comment => new CommentViewModel()
                {
                    Author = comment.User.UserName,
                    AuthorId = comment.User.Id,
                    CommentText = comment.CommentText,
                    CreatedOn = comment.CreatedOn
                }).ToList()
            };

            if (movie == null)
            {
                return HttpNotFound();
            }
            return View(model);
        }
예제 #2
0
        private ActionResult Votes(int? id, int islLke)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Home");
            }

            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var movie = db.Movies.Find(id);
            if (movie == null)
            {
                return HttpNotFound();
            }

            var user = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);
            if (user == null)
            {
                return HttpNotFound();
            }

            var vote = db.Votes.FirstOrDefault(x => x.User.UserName == User.Identity.Name && x.MovieId == id);
            if (vote == null)
            {
                vote = new Vote();
            }

            vote.UserId = User.Identity.GetUserId();
            vote.Movie = movie;
            vote.IsLike = islLke;

            db.Votes.Add(vote);
            db.SaveChanges();

            var model = new MovieFullDetails()
            {
                Id = movie.Id,
                Votes = movie.Votes
            };

            return PartialView("_VotesPartial", model);
            //return RedirectToAction("Details/" + movie.Id);
        }