コード例 #1
0
        public IActionResult AddReview(AddReviewModel model)
        {
            if (ModelState.IsValid)
            {
                var newReview = new Review
                {
                    BookID         = _context.Books.Single(x => x.Id == model.BookID).Id,
                    Rating         = model.Rating,
                    CustomerReview = model.CustomerReview,
                    ReviewDate     = DateTime.Now
                };

                try
                {
                    var addReview = _context.Review.Add(newReview);
                    _context.SaveChanges();
                    ViewBag.Message = "Review created successfully.";
                    //model.BookID = _context.Books.First().Id;
                    return(RedirectToAction("ReadReviews", new { id = newReview.BookID }));
                }
                catch (Exception ex)
                {
                    //Refactor to display proper message
                    ViewBag.Message = ex.Message;
                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
コード例 #2
0
        public IActionResult AddReview(int id)
        {
            AddReviewModel model = new AddReviewModel
            {
                BookID = id
            };

            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> AddReview([FromBody] AddReviewModel model)
        {
            var review = _mapper.Map <Review>(model);

            review.CreatedById = 1;
            var reviewToSave = _mapper.Map <ReviewEntity>(review);
            await _unitOfWork.ReviewRepository.AddAsync(reviewToSave);

            await _unitOfWork.Commit();

            return(Ok());
        }
コード例 #4
0
 public ActionResult Index([Bind(Exclude = "Id")] AddReviewModel userReviewVM, string movie)
 {
     AuthenticateUser();
     if (ModelState.IsValid)
     {
         UserReview userReview = new UserReview();
         using (var context = new MovieReviewsDbContext())
         {
             try
             {
                 var             currentUser = User.Identity.GetUserId();
                 var             movieInDb   = context.Movies.Where(o => o.MovieName == userReviewVM.MovieName).SingleOrDefault();
                 ApplicationUser user        = context.Users.Where(usr => usr.Id == currentUser).SingleOrDefault();
                 userReview.User   = user;
                 userReview.Movie  = movieInDb;
                 userReview.Review = userReviewVM.Review;
                 ModelState.AddModelError("MovieName", "Wrong movie name");
                 if (userReview.Movie == null)
                 {
                     return(View(userReview));
                 }
                 context.UserReviews.Add(userReview);
                 movieInDb.UserReviews.Add(userReview);
                 context.SaveChanges();
             }
             catch (DbEntityValidationException dbEx)
             {
                 foreach (var validationErrors in dbEx.EntityValidationErrors)
                 {
                     foreach (var validationError in validationErrors.ValidationErrors)
                     {
                         Trace.TraceInformation("Property: {0} Error: {1}",
                                                validationError.PropertyName,
                                                validationError.ErrorMessage);
                     }
                 }
             }
             // return Content("<script>alert('Done!')</script>");
             return(RedirectToAction("Movies", "Home"));
         }
     }
     else
     {
         if (movie != null)
         {
             ViewBag.movieName = movie;
         }
         return(View(userReviewVM));
     }
 }
コード例 #5
0
        public async Task <IActionResult> AddReview([FromForm] AddReviewModel addReview)
        {
            if (addReview == null ||
                addReview.UserId == Guid.Empty ||
                addReview.PlaceId == Guid.Empty)
            {
                return(BadRequest("Invalid Request Data"));
            }

            if (string.IsNullOrWhiteSpace(addReview.Title) || string.IsNullOrWhiteSpace(addReview.Content))
            {
                return(BadRequest("Title and Content should be there"));
            }

            try
            {
                if (!dbContext.Places.Any(p => p.Id == addReview.PlaceId))
                {
                    return(BadRequest("Invalid Place"));
                }
                var user = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == addReview.UserId);

                if (user == null)
                {
                    return(BadRequest("Invalid User"));
                }

                user.Score += 100;

                var review = new Review
                {
                    Title      = addReview.Title,
                    Content    = addReview.Content,
                    PlaceId    = addReview.PlaceId,
                    ReviewerId = addReview.UserId,
                    ReviewedOn = DateTime.UtcNow,
                    Rating     = addReview.Rating
                };

                dbContext.Reviews.Add(review);
                dbContext.SaveChanges();

                return(Json(review));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #6
0
ファイル: ReviewsController.cs プロジェクト: Burion/Admin
        public async Task <Result> AddReview(AddReviewModel model)
        {
            var r    = _mapper.Map <Review>(model);
            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            r.UserId    = user.Id;
            r.CompanyId = ctx.CompanyUsers.Single(cu => cu.UserId == user.Id).CompanyId;
            ctx.Reviews.Add(r);
            await ctx.SaveChangesAsync();

            return(new Result()
            {
                Successful = true
            });
        }
コード例 #7
0
        public async Task <IActionResult> Post(AddReviewModel request)
        {
            var reviewRepository = _repositoryFactory.RepositoryAsync <Domain.Review>();

            var review = Domain.Review
                         .Load(request.Content)
                         .AddAuthor(request.UserId)
                         .AddProduct(request.ProductId);

            var result = await reviewRepository.AddAsync(review);

            return(Ok(new AddReviewViewModel {
                Result = result.ToDto()
            }));
        }
コード例 #8
0
        public ActionResult Index(string movie)
        {
            //UserReview review = new UserReview();
            //Movie movieInDb;
            AuthenticateUser();
            AddReviewModel userReviewVM = new AddReviewModel();

            using (var context = new MovieReviewsDbContext())
            {
                // movieInDb = context.Movies.Where(mv => mv.MovieName == movie).SingleOrDefault();

                userReviewVM.MovieName = movie;
            }
            if (userReviewVM.MovieName != null)
            {
                return(View(userReviewVM));
            }
            return(Content("<script>alert('Movie not found');</script>"));
        }
コード例 #9
0
        private async Task <IActionResult> AddToObject(string objCode, AddReviewModel model)
        {
            if (model.Rate < 0 || model.Rate > 5)
            {
                return(BadRequest("model is invalid"));
            }

            if (model.PlaceId <= 0)
            {
                return(BadRequest("model is invalid"));
            }

            if (!await HasObject(objCode, model.PlaceId))
            {
                return(BadRequest("No such place"));
            }

            ReviewDto dto =
                new ReviewDto()
            {
                Text       = model.Text,
                IsVisible  = false,
                Rate       = model.Rate,
                PlaceType  = objCode,
                PlaceId    = model.PlaceId,
                UserId     = this.GetUserId(),
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Id         = 0
            };

            var add =
                await Add(dto);

            await RecalculateRating(objCode, model.PlaceId);

            return(Ok(add));
        }
コード例 #10
0
        public IActionResult PostReview([FromBody] AddReviewModel model)
        {
            var currentUserId = int.Parse(User.Identity.Name);
            var review        = _mapper.Map <Review>(model);

            if (User.IsInRole(Role.Customer))
            {
                review.CustomerId = _forumService.getCustomerId(currentUserId);
            }
            if (User.IsInRole(Role.Driver))
            {
                review.DriverId = _forumService.getDriverId(currentUserId);
            }

            try
            {
                _forumService.CreateReview(review);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { mesasge = ex.Message }));
            }
        }
コード例 #11
0
 public Task <IActionResult> AddToEvent([FromBody] AddReviewModel model)
 => AddToObject(PlaceTypesConfig.EventCode, model);
コード例 #12
0
 public Task <IActionResult> AddToRoute([FromBody] AddReviewModel model)
 => AddToObject(PlaceTypesConfig.RouteCode, model);
コード例 #13
0
 public Task <IActionResult> AddToAttraction([FromBody] AddReviewModel model)
 => AddToObject(PlaceTypesConfig.AttractionCode, model);
コード例 #14
0
 public Task <IActionResult> AddToHotel([FromBody] AddReviewModel model)
 => AddToObject(PlaceTypesConfig.HotelCode, model);