Example #1
0
        public ReviewViewModel Add(ReviewSubmissionViewModel review)
        {
            // Instantiate a reference for the product
            var product = Reference.Create($"product://{review.ProductCode}");

            // Instantiate a reference for the contributor
            var contributor = Reference.Create($"visitor://{review.Nickname}");

            // Add the contributor's rating for the product
            var submittedRating = new Rating(contributor, product, new RatingValue(review.Rating));
            var storedRating    = _ratingService.Add(submittedRating);

            // Compose a comment representing the review
            var comment   = new Comment(product, contributor, review.Body, true);
            var extension = new Review
            {
                Title    = review.Title,
                Location = review.Location,
                Nickname = review.Nickname,
                Rating   = new ReviewRating
                {
                    Value     = review.Rating,
                    Reference = storedRating.Id.Id
                }
            };

            var result = _commentService.Add(comment, extension);

            _cache.Remove(CachePrefix + review.ProductCode);
            // Add the composite comment for the product
            return(ViewModelAdapter.Adapt(result));
        }
        /// <summary>
        /// Adds a rating with the Episerver Social Framework for the
        /// target and user reference specified.
        /// </summary>
        /// <param name="user">the reference of rater who submitted the rating.</param>
        /// <param name="target">the reference of target the rating applies to.</param>
        /// <param name="value">the rating value that was submitted by the rater.</param>
        /// <exception cref="SocialRepositoryException">Thrown when errors occur communicating with
        /// the Social cloud services.</exception>
        public void AddRating(string user, string target, int value)
        {
            try
            {
                var rating = ratingService.Add(new Rating(
                                                   Reference.Create(user),
                                                   Reference.Create(target),
                                                   new RatingValue(value)));

                if (rating == null)
                {
                    throw new SocialRepositoryException("The newly submitted rating could not be added. Please try again");
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.", ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException("The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }
        }
        public void AddRating([FromBody] RatingModel ratingModel)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            ratingModel.UserId = userId;
            _ratingService.Add(ratingModel);
        }
Example #4
0
        public async Task <IActionResult> Rating(RatingViewModel rate)
        {
            rate.ProductId = HttpContext.Session.Get <int>(CommonConstants.ProductId);
            await _ratingService.Add(rate);

            return(new OkObjectResult(rate));
        }
        public void SendRating(double ratingNumber, int authorId, int newsId)
        {
            var newsViewModel = newsService.Get(newsId);
            var tempRating    = newsViewModel.Ratings.FirstOrDefault(x => x.UserId == authorId && x.NewsId == newsId);

            if (tempRating != null)
            {
                ratingService.Edit(new RatingViewModel()
                {
                    NewsId       = newsId,
                    RatingNumber = ratingNumber,
                    Id           = tempRating.Id,
                    UserId       = authorId
                });
            }
            else
            {
                ratingService.Add(new RatingViewModel()
                {
                    NewsId       = newsId,
                    RatingNumber = ratingNumber,
                    UserId       = authorId
                });
            }
        }
Example #6
0
        public IActionResult Create([FromBody] EditRatingResource rating)
        {
            AppLogger.LogResourceRequest(nameof(Create), base.GetUsernameForRequest());

            try
            {
                var result = _ratingService.ValidateResource(rating);

                if (!result.IsValid)
                {
                    GetErrorsForModelState(result.ErrorMessages);
                }

                if (ModelState.IsValid)
                {
                    _ratingService.Add(rating);

                    return(CreatedAtAction(nameof(Create), rating));
                }

                return(ValidationProblem());
            }
            catch (Exception ex)
            {
                return(BadRequestExceptionHandler(ex, nameof(Create)));
            }
        }
Example #7
0
        public IActionResult Post([FromBody] RatingAddViewModel ratingAddViewModel)
        {
            ratingAddViewModel.UserId = Convert.ToInt32(User.Identity.Name);
            _ratingService.Add(ratingAddViewModel);

            return(StatusCode(StatusCodes.Status200OK));
        }
Example #8
0
 public IActionResult Add(int recipeId, int value)
 {
     if (recipeId != 0)
     {
         var userId = Usermanager.GetUserId(User);
         RatingService.Add(value, userId, recipeId);
     }
     return(RedirectToAction("Detailss", "Home", new { id = recipeId }));
 }
Example #9
0
        public IActionResult Rate(RatingDto ratingDto)
        {
            ratingDto.Url = Uri.UnescapeDataString(ratingDto.Url);
            if (ModelState.IsValid)
            {
                _ratingService.Add(ratingDto);
                return(RedirectToAction(nameof(Success)));
            }

            var errors = ModelState.Values.Select(v => v.Errors).ToList();

            return(View(ratingDto));
        }
Example #10
0
        public ActionResult <RatingVM> Create(int productId, RatingVM ratingVM)
        {
            if (!ModelState.IsValid || productId <= 0)
            {
                return(BadRequest());
            }
            var result = _ratingSer.Add(productId, ratingVM);

            if (result == null)
            {
                return(Problem("Can't add rating"));
            }
            return(CreatedAtAction(nameof(Create), result));
        }
        public ActionResult VoteMoviesSeries(int id, short rate)
        {
            User   user   = _userService.GetUsersByUserName(User.Identity.GetUserName());
            Rating rating = _ratingService.GetRatingByUserAndMovie(user.UserID, id);

            if (rating == null)
            {
                rating = new Rating();
                rating.MoviesSeriesID = id;
                rating.UserID         = user.UserID;
                rating.Score          = rate;
                _ratingService.Add(rating);
            }
            else
            {
                rating.MoviesSeriesID = id;
                rating.UserID         = user.UserID;
                rating.Score          = rate;
                _ratingService.Update(rating);
            }

            ViewBag.rating = rating;
            return(View());
        }
Example #12
0
 public IActionResult Post([FromBody] Rating model)
 {
     if (ModelState.IsValid)
     {
         var result = _ratingService.Add(model);
         if (result)
         {
             return(Ok(result));
         }
         else
         {
             return(BadRequest("No se ha podido puntuar"));
         }
     }
     else
     {
         return(BadRequest("No se ha podido puntuar"));
     }
 }
        public void Create([FromBody] EditRatingDTO ratingDTO)
        {
            try
            {
                var result = _ratingService.ValidateResource(ratingDTO);
                if (!result.IsValid)
                {
                }

                if (result.IsValid)
                {
                    _ratingService.Add(ratingDTO);
                }
            }
            catch (Exception)
            {
                // Implement logging MS
                //throw StatusCode(500, "Internal server error");
            }
        }
Example #14
0
 public ActionResult Post(Rating rating)
 {
     try
     {
         IRatingService ratingService = InstanceFactory.GetInstance <IRatingService>();
         if (rating.ID < 1)
         {
             ratingService.Add(rating);
             return(Ok(rating));
         }
         else
         {
             return(BadRequest("Yanlış istek."));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #15
0
        public ActionResult Submit(LikeButtonBlockViewModel likeButtonBlock)
        {
            var targetPageRef = Reference.Create(PermanentLinkUtility.FindGuid(likeButtonBlock.Link).ToString());
            var raterUserRef  = GetRaterRef();

            try
            {
                // Add the rating using the Episerver Social Rating service
                var addedRating = _ratingService.Add(
                    new Rating(
                        raterUserRef,
                        targetPageRef,
                        new RatingValue(LikedRating)
                        )
                    );
            }
            catch (Exception)
            {
                // The rating service may throw a number of possible exceptions
                // should handle each one accordingly -- see rating service documentation
            }

            return(Redirect(UrlResolver.Current.GetUrl(likeButtonBlock.Link)));
        }