public ActionResult AddReview(AddReviewVM data, HttpPostedFileBase file)
 {
     data.GameReview.ReviewDate = DateTime.Now;
     if (data.GameReview.Game.GameCover == null)
     {
         data.GameReview.Game.GameCover = new GameCover();
     }
     try
     {
         if (file.ContentLength > 0)
         {
             var fileName = Path.GetFileName(file.FileName);
             var path     = Path.Combine(Server.MapPath("~/imgs/"), fileName);
             data.GameReview.Game.GameCover.GameCoverUrl = "imgs/" + fileName;
             file.SaveAs(path);
         }
     } catch
     {
         data.GameReview.Game.GameCover.GameCoverUrl = "imgs/default.png";
         _repo.ContributorAddReview(data.GameReview);
         return(RedirectToAction("Index", "Reviews"));
     }
     _repo.ContributorAddReview(data.GameReview);
     return(RedirectToAction("Index", "Reviews"));
 }
        public ActionResult AddReview()
        {
            var model = new AddReviewVM();

            model.RatingList   = _repo.GetAllRatings();
            model.PlatformList = _repo.GetAllPlatforms();
            return(View(model));
        }
        public ActionResult EditReview(int id)
        {
            var model    = new AddReviewVM();
            var reviewTo = _repo.GetReviewById(id);

            if (HttpContext.User.IsInRole("admin") || int.Parse(HttpContext.User.Identity.GetAuthorId().Remove(0, 10)) == reviewTo.AuthorId)
            {
                model.GameReview   = _repo.GetReviewById(id);
                model.PlatformList = _repo.GetAllPlatforms();
                model.RatingList   = _repo.GetAllRatings();
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Reviews"));
            }
        }
        public ActionResult EditReview(AddReviewVM editedReview, HttpPostedFileBase file)
        {
            try
            {
                if (file.ContentLength > 0)
                {
                    editedReview.GameReview.Game.GameCover = new GameCover();
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/imgs/"), fileName);
                    editedReview.GameReview.Game.GameCover.GameCoverUrl = "imgs/" + fileName;
                    file.SaveAs(path);
                }
            }
            catch
            {
                _repo.ContributorEditReview(editedReview.GameReview);
            }
            _repo.ContributorEditReview(editedReview.GameReview);

            return(RedirectToAction("Index", "Reviews"));
        }
Esempio n. 5
0
 public IActionResult Review(AddReviewVM model)
 {
     return(View("Review"));
 }