Example #1
0
 public ReviewModel Create(MovieReview mr)
 {
     return new ReviewModel()
         {
             Id = mr.Id,
             ReviewedDate = mr.ReviewedDate,
             Rating = mr.Rating,
             TagLine = mr.TagLine,
             Review = mr.Review,
             Reviewer = mr.Reviewer.Name,
             Movie = mr.Movie == null ? string.Empty : mr.Movie.Title
         };
 }
Example #2
0
        public ActionResult Edit(int id, ReviewModel reviewModel)
        {
            if (ModelState.IsValid)
            {
                MovieReview review;

                if (id == default(int))
                {
                    review = new MovieReview();
                    if (!ModelFactoryInstance.TryParse(review, reviewModel, _unitOfWork, ModelState))
                    {
                        return View(reviewModel);
                    }
                    review.State = ObjectState.Added;
                    _reviewRepo.Insert(review);
                }
                else
                {
                    review = _reviewRepo.FindById(id);
                    if (!ModelFactoryInstance.TryParse(review, reviewModel, _unitOfWork, ModelState))
                    {
                        return View(reviewModel);
                    }
                    review.State = ObjectState.Modified;
                    _reviewRepo.Update(review);
                }
                _unitOfWork.Save();
                return RedirectToAction("Index");
            }

            return View(reviewModel);
        }
Example #3
0
 public bool TryParse(MovieReview review, ReviewModel reviewModel, IUnitOfWork _unitOfWork, ModelStateDictionary modelState)
 {
     bool isValid = true;
     var movie = _unitOfWork.Repository<Movie>().Query()
         .Filter(m => m.Title.ToLower() == reviewModel.Movie.ToLower())
         .FirstOrDefault();
     if (movie == null)
     {
         modelState.AddModelError("Movie", "Not a valid Movie");
         isValid = false;
     }
     var reviewer = _unitOfWork.Repository<Reviewer>().Query()
         .Filter(r => r.Name.ToLower() == reviewModel.Reviewer.ToLower())
         .FirstOrDefault();
     if (reviewer == null)
     {
         modelState.AddModelError("Reviewer", "Not a valid Reviewer");
         isValid = false;
     }
     review.Movie = movie;
     review.Reviewer = reviewer;
     review.ReviewedDate = reviewModel.ReviewedDate;
     review.TagLine = reviewModel.TagLine;
     review.Rating = reviewModel.Rating;
     review.Review = reviewModel.Review;
     return isValid;
 }