Exemple #1
0
        //API to Add new review for particular movie....
        public string AddReview(AddReviewRequest request)
        {
            if (request != null)
            {
                Review addingReview = new Review();
                //addingReview.Id = request.ReviewId;(identity element)
                var movies = _db.Movie.ToList();
                int count  = 0;
                foreach (var item in movies)
                {
                    count++;
                    if (request.ReviewedMovieId == item.Id)
                    {
                        addingReview.MovieId = request.ReviewedMovieId;
                        break;
                    }
                    else if (count == movies.Count)
                    {
                        return("MovieId Given Is Invalid.Please,Enter Valid movieId(Kindly,check with movies API for information");
                    }
                }

                addingReview.Comment = request.ReviewComment;
                _db.Review.Add(addingReview);
                _db.SaveChanges();
                return("Successfully Review Added");
            }
            return("Unsuccessfully,Due to Null value.Please,enter valid contents");
        }
        public async Task <BaseResponse <bool> > Handle(AddReviewRequest request, CancellationToken cancellationToken)
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                var movie = await _movieRepository.Get(request.MovieId);

                if (movie == null)
                {
                    response.Errors.Add("Movie  not found");
                    return(response);
                }
                var review = new Review(_guidGenerator.Create(), request.UserId, request.Note, request.Rating);
                movie.AddReview(review);

                await _movieRepository.UpdateMovie(movie);

                response.Data = true;
            }
            catch (Exception ex)
            {
                response.Errors.Add(ex.Message);
                _logger.LogError("--- Adding Review Error", "User Id:" + request.UserId, "Message: " + ex.Message);
            }
            return(response);
        }
        public async Task <IActionResult> Add([FromBody] AddReviewRequest reviewRequest)
        {
            if (reviewRequest == null || reviewRequest.Review == null)
            {
                return(BadRequest());
            }

            var review = reviewRequest.Review;

            if (string.IsNullOrEmpty(review.Title))
            {
                return(Ok(new { Success = false }));
            }

            var successfulCaptcha = await GoogleController.ValidateRecaptcha(reviewRequest.RecaptchaResponse);

            if (!successfulCaptcha)
            {
                return(Ok(new { Success = false }));
            }

            // now that we've successfully passed all validations, get the Author id
            // from the User object and add the review
            var googleId = GetUserGoogleId();

            if (googleId == null)
            {
                return(BadRequest());
            }

            var author = await RRRepo.GetAuthorByGoogleId(googleId);

            var authorsReviews = await RRRepo.GetReviewsByAuthorId(author.Id);

            if (authorsReviews?.FirstOrDefault(rev => rev.RestroomId == review.RestroomId) != null)
            {
                return(Ok(new {
                    Success = false,
                    Error = "ALREADY_EXISTS"
                }));
            }

            var restroom = await RRRepo.GetById(review.RestroomId);

            review.Author   = author;
            review.Restroom = restroom;

            await RRRepo.AddReview(review);

            return(Ok(new {
                Success = true,
                Review = review,
            }));
        }
 public bool AddReview(AddReviewRequest request)
 {
     if (request != null)
     {
         Review review = new Review();
         review.ReviewDetails = request.Review;
         review.MovieId       = request.MovieId;
         _db.Reviews.Add(review);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
Exemple #5
0
 public bool AddReviews(AddReviewRequest request)
 {
     if (request != null)
     {
         Reviews review = new Reviews();
         review.HonestReviews = request.Reviews;
         review.MoviesId      = request.MoviesId;
         _db.ReviewsTable.Add(review);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
Exemple #6
0
        public async Task <IActionResult> Add([FromBody] AddReviewRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _reviewService.AddAsync(request);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
        public ActionResult SubmitReview(Review review)
        {
            var reviewsServiceProvider = new ReviewsServiceProvider();

            var addReviewRequest = new AddReviewRequest(review.Text, DateTime.Now, review.Author, review.Score, review.ProductId);

            AddReviewResult addReviewResult = reviewsServiceProvider.AddReview(addReviewRequest);

            if (!addReviewResult.Success)
            {
                // todo: log here
            }

            this.Response.Redirect(new Uri(this.Request.UrlReferrer.ToString()).ToString());

            return(null);
        }
        public async Task <IActionResult> AddReview([FromBody] AddReviewRequest request)
        {
            // If user logged in get id from token.
            //  var userId = _identityService.GetUserIdentity();
            var userId = Guid.NewGuid();

            request.UserId = userId;
            var response = await _mediator.Send(request);

            if (!response.HasError)
            {
                return(Ok(response));
            }
            else
            {
                return(BadRequest(response));
            }
        }
Exemple #9
0
        public async Task <BaseResponse> AddAsync(AddReviewRequest request)
        {
            var userReview = await _reviewRepository.GetRestaurantUserReviewAsync(_loggedUser.Id, request.RestaurantId);

            if (userReview != null)
            {
                return(new BaseResponse("Review is already added"));
            }

            var review = _mapper.Map <AddReviewRequest, Review>(request);

            review.CreatedById = _loggedUser.Id;

            await _reviewRepository.AddAsync(review);

            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }
 public bool AddReviews(AddReviewRequest request)
 {
     if (request != null)
     {
         List <Movie> movie;
         //Check if movie id is available to add review
         movie = _db.Movies.Where(a => a.Id == request.movieId).ToList();
         //if movie id available - add review - return true
         if (movie != null)
         {
             foreach (var item in movie)
             {
                 Review review = new Review();
                 review.ReviewName = request.reviewData;
                 review.moviesId   = request.movieId;
                 _db.Reviews.Add(review);
                 _db.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
     return(false);
 }
        internal Result AddReview(AddReviewRequest reqiest)
        {
            try
            {
                User user = context.Users.FirstOrDefault(a => a.Id == reqiest.userId);
                Room room = user.Room;

                if (!room.Room2Beverages.Any(a => a.BeverageId == reqiest.beverageId))
                {
                    return(new Result(ResultStatus.ERROR, "Beverage not in current room"));
                }

                if (room.Room2Beverages.Any(a => a.BeverageId == reqiest.beverageId && a.IsLocked))
                {
                    return(new Result(ResultStatus.ERROR, "Beverage closed for reviewing"));
                }

                if (reqiest.parts.Any(a => a.score < 0))
                {
                    return(new Result(ResultStatus.ERROR, "Score cannot be negative"));
                }

                string         resultmessage = "";
                BeverageReview review        = new BeverageReview();
                decimal        total         = 0;
                foreach (var part in reqiest.parts)
                {
                    var reviewType = room.Room2ReviewTypes.FirstOrDefault(a => a.ReviewTypeId == part.reviewTypeId);
                    total += (reviewType.MaxValue / 100m) * part.score;
                }

                total = Math.Round(total, 2);

                if (!user.BeverageReviews.Any(a => a.BeverageId == reqiest.beverageId))
                {
                    EntitySet <ReviewPart> partsToAdd = new EntitySet <ReviewPart>();
                    partsToAdd.AddRange(reqiest.parts.Select(a => new ReviewPart()
                    {
                        ReviewTypeId = a.reviewTypeId,
                        Score        = a.score
                    }));

                    review = new BeverageReview()
                    {
                        BeverageId  = reqiest.beverageId,
                        DateCreated = DateTime.Now,
                        RoomId      = room.Id,
                        TotalScore  = total,
                        ReviewParts = partsToAdd,
                        Comment     = reqiest.comment
                    };
                    user.BeverageReviews.Add(review);

                    resultmessage = "Review Added";
                }
                else
                {
                    review            = user.BeverageReviews.FirstOrDefault(a => a.BeverageId == reqiest.beverageId);
                    review.TotalScore = total;
                    review.Comment    = reqiest.comment;


                    foreach (var part in reqiest.parts)
                    {
                        ReviewPart p = review.ReviewParts.FirstOrDefault(a => a.ReviewTypeId == part.reviewTypeId);
                        p.Score = part.score;
                    }

                    resultmessage = "Review Updated";
                }

                context.SubmitChanges();
                beerhub             hub   = new beerhub();
                Beverage            b     = room.Room2Beverages.FirstOrDefault(a => a.BeverageId == reqiest.beverageId).Beverage;
                List <ReviewTypeVM> types = room.Room2ReviewTypes.Select(a => new ReviewTypeVM(a)).ToList();
                hub.PushReview(room.Code, new BeverageReviewVM(b, types, user, review));


                return(new Result(ResultStatus.SUCCESS, resultmessage));
            }
            catch (Exception ex)
            {
                return(new UserRoomModel(ResultStatus.ERROR, ex.Message));
            }
        }
 public async Task <IActionResult> Post([FromServices] IMediator eventor, AddReviewRequest request, CancellationToken cancellationToken) =>
 await eventor.SendStream <AddReviewRequest, AddReviewResponse>(request, x => x.Result);
 public IActionResult AddReview(AddReviewRequest data)
 {
     return(Ok(repository.AddReview(data)));
 }
        public HttpResponseMessage AddReview(AddReviewRequest reqiest)
        {
            Result result = dal.AddReview(reqiest);

            return(ApiTools.CreateResponse(result, Request));
        }
 public virtual AddReviewResult AddReview(AddReviewRequest request)
 {
     return(this.RunPipeline <AddReviewRequest, AddReviewResult>(Constants.PipelineNames.AddProductReview, request));
 }