Example #1
0
        public void AddTestReviews()
        {
            if (_reviewRepo.GetAll().Count() > 0)
            {
                return;
            }

            var john        = _userManager.FindByNameAsync("*****@*****.**").Result;
            var jane        = _userManager.FindByNameAsync("*****@*****.**").Result;
            var johnReview1 = CreateTestReview(1, john, 1, "Green Apple", 100, "Super delicious!");
            var janeReview1 = CreateTestReview(2, jane, 2, "Coca-cola", 0, "Everything about this product sucks...");

            _reviewRepo.Add(johnReview1);
            _reviewRepo.Add(janeReview1);
        }
        public ActionResult ReviewUniversity(Review model, int id)
        {
            model.UniversityId = id;
            if (model.Value > 5 || model.Value < 1)
            {
                model.Value = 5;
            }

            model.UserId = User.Identity.GetUserId();
            _reviewRepository.Add(model);
            Task task = Task.Run(async() => await _reviewRepository.Commit());

            task.Wait();
            return(RedirectToAction("Details", "Universities", new { id = id }));
        }
Example #3
0
        public async Task <IActionResult> AddReview(ReviewForm model)
        {
            if (ModelState.IsValid)
            {
                var user = await _workContext.GetCurrentUser();

                model.ReviewerName = user.FullName; // Otherwise ReviewerName is null
                var review = new Review
                {
                    Rating       = model.Rating,
                    Title        = model.Title,
                    Comment      = model.Comment,
                    ReviewerName = user.FullName,
                    EntityId     = model.EntityId,
                    EntityTypeId = model.EntityTypeId,
                    UserId       = user.Id,
                };

                _reviewRepository.Add(review);
                _reviewRepository.SaveChanges();

                return(PartialView("_ReviewFormSuccess", model));
            }
            return(PartialView("_ReviewForm", model));
        }
Example #4
0
 public Review Create(Review review, Guid idOfReserveAssociated)
 {
     try
     {
         Reserve reserveAssociated = reserveManagementLogic.GetById(idOfReserveAssociated);
         VerifyIfExistReviewForReserve(idOfReserveAssociated);
         review.IdOfReserve           = idOfReserveAssociated;
         review.NameOfWhoComments     = reserveAssociated.Name;
         review.LastNameOfWhoComments = reserveAssociated.LastName;
         Lodging lodgingOfReview = reserveAssociated.LodgingOfReserve;
         review.LodgingOfReview = lodgingOfReview;
         review.VerifyFormat();
         reviewRepository.Add(review);
         double averageReviewScoreUpdated = reviewRepository.GetAverageReviewScoreByLodging(lodgingOfReview.Id);
         lodgingManagementLogic.UpdateAverageReviewScore(lodgingOfReview, averageReviewScoreUpdated);
         return(review);
     }
     catch (ReviewException e)
     {
         throw new DomainBusinessLogicException(e.Message);
     }
     catch (ClientBusinessLogicException e)
     {
         throw new ClientBusinessLogicException(MessageExceptionBusinessLogic.ErrorCreatingReview, e);
     }
     catch (DomainBusinessLogicException e)
     {
         throw new DomainBusinessLogicException(e.Message);
     }
     catch (ServerException e)
     {
         throw new ServerBusinessLogicException("No se puede crear la review debido a que ha ocurrido un error.", e);
     }
 }
Example #5
0
        public Review Add(Review review)
        {
            var addedEntity = _reviewRepository.Add(review);

            _sub.OnNext(review);
            return(review);
        }
        public IActionResult Post(int companyId, [FromBody] ReviewDto dto)
        {
            try
            {
                var customerExtarnalId = User.GetExternalId();
                if (customerExtarnalId != dto.CustomerId)
                {
                    return(Forbid());
                }

                var customer = _customerRepository.GetByExternalId(customerExtarnalId);
                if (customer == null)
                {
                    return(Forbid());
                }

                if (dto.Rating < 1 || dto.Rating > 5)
                {
                    return(BadRequest("rating cannot be less than 1 and greater than 5"));
                }

                dto.Date = DateTime.Now;
                var model = new Core.Entities.Review();
                DtoToReviewMapper.Map(dto, model);
                _reviewRepository.Add(model);
                _unitOfWork.Save();
                dto.Id = model.Id;
                return(Created($"api/companies/{companyId}/reviews/{model.Id}", dto));
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"unhandled exception");
                return(StatusCode(500, ex));
            }
        }
Example #7
0
        public ActionResult Add(ReviewDTO reviewDTO)
        {
            TempData["ActivePanel"] = "review";
            var product = _productRepo.FindById(reviewDTO.ProductId);

            if (product == null)
            {
                return(View("Error"));
            }

            if (!ModelState.IsValid)
            {
                TempData["SaveSuccess"] = "false";
                return(RedirectToAction("detail", "product", new { metaTitle = product.MetaTitle }));
            }

            reviewDTO.UserId = User.Identity.GetUserId();

            var result = _reviewRepo.Add(reviewDTO);

            if (!result)
            {
                TempData["SaveSuccess"] = "false";
                return(RedirectToAction("detail", "product", new { metaTitle = product.MetaTitle }));
            }

            TempData["SaveSuccess"] = "true";
            return(RedirectToAction("detail", "product", new { metaTitle = product.MetaTitle }));
        }
Example #8
0
        public async Task <ActionResult <Review> > PostReview(Review review)
        {
            reviewRepo.Add(review);
            await reviewRepo.SaveChangesAsync();

            return(CreatedAtAction("GetReview", new { id = review.ReviewId }, review));
        }
Example #9
0
        public ActionResult Review(int id, ReviewAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var review = new Review()
                {
                    BenchId     = id,
                    Description = viewModel.Description,
                    Rating      = viewModel.Rating,
                    UserId      = ((CustomPrincipal)User).Id,
                    Date        = DateTimeOffset.Now
                };

                if (reviewRepo.Add(review))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Unable to add review.");
                }
            }
            else
            {
                ModelState.AddModelError("", "All fields are required.");
            }
            return(View(viewModel));
        }
Example #10
0
        public void Execute()
        {
            ValidateRequest();

            if (Match)
            {
                var review = _reviewRepository.Find(Request.UserId, Request.MovieId);

                if (review != null)
                {
                    review.MovieId = Request.MovieId;
                    review.UserId  = Request.UserId;
                    review.Rating  = Request.Rating;

                    _reviewRepository.Edit(review);
                }
                else
                {
                    var newReview = new Review()
                    {
                        MovieId = Request.MovieId,
                        UserId  = Request.UserId,
                        Rating  = Request.Rating
                    };

                    _reviewRepository.Add(newReview);
                }

                _reviewRepository.Commit();
            }
        }
Example #11
0
        public async Task <bool> Add(ZabotaReview review)
        {
            review.Date = DateTimeOffset.UtcNow;
            await _reviewRepository.Add(review);

            return(true);
        }
Example #12
0
        public IActionResult AddReview(Review ReviewIn, string movieItems)
        {
            User currentUser = _customerList.GetUserByUsername(HttpContext.Session.GetString("Username"));

            if (currentUser != null)
            {
                ReviewIn.Author     = currentUser;
                ReviewIn.Movie      = _movieList.GetMovie(int.Parse(movieItems));
                ReviewIn.MovieTitle = ReviewIn.Movie.MovieTitle;
                if (ReviewIn.Movie == null)
                {
                    TempData["Failure"] = "The name: " + ReviewIn.MovieTitle + "was not found, please re-enter";
                    return(RedirectToAction("AddReview"));
                }
                _reviewList.Add(ReviewIn);
                IEnumerable <Review> movieReviews = _reviewList.GetMovieReviews(ReviewIn.Movie);

                ReviewIn.Movie.MovieRating = Math.Round((decimal)movieReviews.Average(m => m.StarRating));

                ReviewIn.Movie.NumberOfReviews = movieReviews.Count();
                _context.SaveChanges();
                return(RedirectToAction("ReviewList"));
            }
            else
            {
                return(View("Login"));
            }
        }
Example #13
0
        public IActionResult Add(int id, HomeDetailsViewModel model)
        {
            var book = bookRepository.GetBook(id);

            if (ModelState.IsValid)
            {
                Review newReview = new Review
                {
                    BookId         = book.Id,
                    ReviewComments = model.Review.ReviewComments,
                    Rating         = model.Review.Rating,
                    Book           = model.Book,
                    Id             = model.ReviewId,
                };


                reviewRepository.Add(newReview);


                reviewRepository.GetAllReviews().Where(a => a.BookId == book.Id).ToList();

                var book5 = bookRepository.GetBook(id).Reviews.Where(p => p.Rating == 5).Count();
                var book4 = bookRepository.GetBook(id).Reviews.Where(p => p.Rating == 4).Count();
                var book3 = bookRepository.GetBook(id).Reviews.Where(p => p.Rating == 3).Count();
                var book2 = bookRepository.GetBook(id).Reviews.Where(p => p.Rating == 2).Count();
                var book1 = bookRepository.GetBook(id).Reviews.Where(p => p.Rating == 1).Count();


                float total        = ((book1 * 1) + (book2 * 2) + (book3 * 3) + (book4 * 4) + (book5 * 5));
                var   totalReviews = bookRepository.GetBook(id).Reviews.Count();
                float average      = total / totalReviews;

                BookAverageRating AvgRating = new BookAverageRating
                {
                    AverageRating = average,
                    BookId        = book.Id
                };

                var avgRating = bookAverageRatingRepository.GetAllAverageRating().Where(a => a.BookId == id).Count();

                /*BookAverageRating newAvgRating = new BookAverageRating
                 * {
                 *  Id = book.BookAverageRating.Id
                 * };*/

                if (avgRating == 0)
                {
                    bookAverageRatingRepository.Add(AvgRating);
                }
                else
                {
                    bookAverageRatingRepository.Delete(AvgRating.Id);
                    bookAverageRatingRepository.Add(AvgRating);
                }
                return(RedirectToAction("List", new { id = newReview.BookId }));
            }
            return(View());
        }
        public void Add(Review review)
        {
            review.ReviewDate = DateTime.Now;
            var game = _gameRepository.Find(review.GameId);

            review.IsVerifiedOwner = _steamApi.CheckAppOwnershipAsync(review.UserId, game.SteamAppId).Result;
            _reviewRepository.Add(review);
            _reviewRepository.Save();
        }
Example #15
0
        public void ReportAbuse(string reviewId, string authorId, string authorName, string authorLocation)
        {
            // Validate Incoming parameters
            if (string.IsNullOrEmpty(reviewId))
            {
                throw new ArgumentNullException("reviewId");
            }
            if (string.IsNullOrEmpty(authorId))
            {
                throw new ArgumentNullException("authorId");
            }
            if (string.IsNullOrEmpty(authorName))
            {
                throw new ArgumentNullException("authorName");
            }
            if (string.IsNullOrEmpty(authorLocation))
            {
                throw new ArgumentNullException("authorLocation");
            }

            var review = FindReviewById(reviewId);

            if (review != null)
            {
                // Skip duplicated Abuse
                var abuseElement = FindReportAbuseByAuthor(reviewId, authorId);
                if (abuseElement != null)
                {
                    return;
                }

                // Post Abuse
                var newAbuseElement = new ReportAbuseElement();
                newAbuseElement.ReviewId = reviewId;
                //newAbuseElement.ReportAbuseElementId = Guid.NewGuid().ToString();
                newAbuseElement.AuthorId = authorId;
                //newAbuseElement.AuthorFN = authorName;
                //newAbuseElement.AuthorLocation = authorLocation;
                //newAbuseElement.Status = "Pending";

                _repository.Add(newAbuseElement);
                _repository.UnitOfWork.Commit();
            }
        }
 public void AddReview(string rating, string title, string text)
 {
     reviewRepository.Add(new Review()
     {
         Id     = Guid.NewGuid(),
         Rating = rating,
         Title  = title,
         Text   = text
     });
 }
Example #17
0
        public void Add(NewReviewDto review)
        {
            ValidateRating(review.Rating);
            var newReview = new Review
            {
                Content      = review.Content, Title = review.Title, Rating = review.Rating,
                EscapeRoomId = review.EscapeRoomId, UserId = review.UserId
            };

            _reviewRepository.Add(newReview);
        }
Example #18
0
        public void AddReview(Guid ownerId, string message)
        {
            GetOwnerByGuid(ownerId);

            reviewRepository.Add(new Review()
            {
                Id      = Guid.NewGuid(),
                Message = message,
                UserId  = ownerId
            });;
        }
        public ActionResult Addnew(ReviewModel model)
        {
            //if (ModelState.IsValid)
            //{
            Review tintuc = new Review()
            {
                Sdate   = DateTime.Now,
                TieuDe  = RejectMarks(model.TieuDe),
                Mota    = model.Mota,
                HinhAnh = (model.HinhAnh).Replace("/files/", ""),
                ChiTiet = ChangeImageSEO(model.ChiTiet, model.TieuDe, ConvertFont(model.TieuDe)),
                //ChiTiet = model.ChiTiet,
                Ok             = false,
                Sapxep         = model.Sapxep,
                Link           = ConvertFont(model.TieuDe),
                SEODescription = model.SEODescription,
                SEOtitle       = model.SEOtitle,
                NguoiTao       = User.Identity.Name
            };

            _reviewRepository.Add(tintuc);
            _unitOfWork.Commit();
            if (model.mySingleField != null)
            {
                #region thêm mới tag

                string[] separators = { "," };
                var      taglist    = model.mySingleField.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                //check null: nếu tồn tại thêm mới bình thường
                if (taglist.Any())
                {
                    foreach (var tag in taglist)
                    {
                        TagTinTuc _tag = new TagTinTuc()
                        {
                            NgayTao = DateTime.Now,
                            IdMenu  = tintuc.id_,                     // id cua tin moi vua them
                            TenTag  = tag.Trim(),
                            Link    = ConvertFont(tag.Trim()),
                            Code    = RejectMarks(tag.Trim())
                        };
                        _tagTinTucRepository.Add(_tag);
                        _unitOfWork.Commit();
                    }
                }
                #endregion
            }
            //}
            //else
            //{
            //    return View("Create", model);
            //}
            return(RedirectToAction("Index"));
        }
Example #20
0
        public void AddReview(string bookName, string authorName, string text, string Title, User user)
        {
            var book   = bookRepository.GetBookByName(bookName);
            var author = authorRepository.GetAuthorByName(authorName);

            reviewRepository.Add(new Review()
            {
                Id = Guid.NewGuid(), Text = text, Book = book, Author = author, Title = Title, User = user
            });
            nrReview++;
        }
        public IActionResult Post([FromBody] Review review)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _reviewRepo.Add(review);
            if (_reviewRepo.SaveAll())
            {
                return(Created("", review));
            }
            return(BadRequest($"failed to add new review"));
        }
Example #22
0
        public async Task <IActionResult> AddReview(string review)
        {
            if (!string.IsNullOrWhiteSpace(review))
            {
                Review rev = new Review()
                {
                    Text = review,
                    User = await _userManager.GetUserAsync(HttpContext.User)
                };
                _reviewRepository.Add(rev);
                _reviewRepository.Commit();
            }

            return(RedirectToAction("Reviews"));
        }
        public async Task <ActionResult <ReviewModel> > Post(ReviewModel model)
        {
            try
            {
                model.Service.ServiceId = 1;
                var review = _mapper.Map <Review>(model);

                if (model.RatingType == null)
                {
                    return(BadRequest("RatingTypeId is required"));
                }
                var ratingType = await _repository.GetRatingTypeAsync(model.RatingType.RatingTypeId);

                if (ratingType == null)
                {
                    return(BadRequest("RatingType could not be found"));
                }
                review.RatingType = ratingType;
                var service = await _repository.GetServiceAsync(model.Service.ServiceId);

                if (service == null)
                {
                    return(BadRequest("Service could not be found"));
                }
                review.Service = service;

                _repository.Add(review);

                if (await _repository.SaveChangesAsync())
                {
                    var url = _linkGenerator.GetPathByAction(HttpContext,
                                                             controller: "Review", action: "Get",
                                                             values: new { reviewId = review.ReviewId, version = "1" });

                    return(Created(url, _mapper.Map <ReviewModel>(review)));
                }
                else
                {
                    return(BadRequest("Failed to save new Review"));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to create Review"));
            }
        }
        public IActionResult Post([FromBody] AddReview review)
        {
            if (review == null)
            {
                return(BadRequest("Review is null."));
            }
            int id = _dataRepository.Add(review);

            if (id == -1)
            {
                return(BadRequest());
            }
            return(CreatedAtRoute(
                       "ReviewGet",
                       new { Id = id },
                       review));
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var review = JsonConvert.DeserializeObject <Reviews>(jsonContent);

            try
            {
                await _reviewRepository.Add(review);

                return(JsonResponse.JsonHttpResponse <object>(true));
            }
            catch (Exception)
            {
                return(JsonResponse.JsonHttpResponse <object>(false));
            }
        }
Example #26
0
        public async Task <ActionResult <ReviewViewModel> > PostReview(ReviewViewModel viewModel)
        {
            try
            {
                var entity = GetMapperReviewViewModelToReview(viewModel);
                var model  = await _reviewRepository.Add(entity);

                return(GetMapperReviewToReviewViewModel(model));
            }
            catch (InvalidDataException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }
Example #27
0
        public async Task <IActionResult> AddReview([FromBody] SaveReviewResource reviewResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var review = mapper.Map <SaveReviewResource, Review>(reviewResource);

            repository.Add(review);
            repository.SetRating(review, onAdd: true);
            await unitOfWork.CompleteAsync();

            review = await repository.GetReview(reviewResource.Id);

            var result = mapper.Map <Review, ReviewResource>(review);

            return(Ok(result));
        }
Example #28
0
 public IActionResult LeaveReview(int recipeId, string recipeTitle, string username, string comment)
 {
     if (ModelState.IsValid)
     {
         reviewRepository.Add(new Review
         {
             RecipeId = recipeId, RecipeTitle = recipeTitle, Username = username, Comment = comment
         });
         return(RedirectToAction("ViewRecipe", new { recipeId = recipeId }));
     }
     else
     {
         return(View("ViewRecipe", new RecipeDetailsViewModel
         {
             Recipe = repository.Recipes.Where(r => r.RecipeId == recipeId).FirstOrDefault(),
             Reviews = reviewRepository.Reviews.Where(r => r.RecipeId == recipeId)
         }));
     }
 }
Example #29
0
        public void Execute(CreateReviewModel createReviewModel)
        {
            var from    = _userRepository.Get(createReviewModel.From);
            var to      = _userRepository.Get(createReviewModel.To);
            var ratings = _reviewRepository
                          .GetAll()
                          .Where(x => x.To.Id.Equals(to.Id))
                          .Select(x => x.Rating)
                          .ToList();

            ratings.Add(createReviewModel.Rating);

            to.UpdateRating(ratings.Average());

            var review = new Review(from, to, createReviewModel.Body, createReviewModel.Rating);

            _reviewRepository.Add(review);

            _unitOfWork.Save();
        }
        public IActionResult Details(ProductDetailsViewModel viewModel, int id)
        {
            if (ModelState.IsValid)
            {
                var newReview = CreateReview(viewModel, id);
                _reviewRepository.Add(newReview);

                return(RedirectToAction("Index", "Review", new { prodId = id, catId = viewModel.ReviewCategoryId, subCatId = viewModel.ReviewSubCategoryId }));
            }

            viewModel.Product             = DetailsGetProductById(id);
            viewModel.SubCategory         = DetailsGetSubCategoryByProductId(id);
            viewModel.Category            = DetailsGetCategoryByProductId(id);
            viewModel.Reviews             = DetailsGetReviewsByProductId(id);
            viewModel.RelatedProducts     = DetailsGetRelatedProductsById(id);
            viewModel.ProductId           = id;
            viewModel.ReviewCategoryId    = _categoryRepository.GetByProductId(id).Id;
            viewModel.ReviewSubCategoryId = _subCategoryRepository.GetByProductId(id).Id;

            return(View(viewModel));
        }