Beispiel #1
0
        public ActionResult Submit(RatingFormViewModel ratingForm)
        {
            ValidateSubmitRatingForm(ratingForm);

            // Add the rating and verify success
            var addRatingSuccess = AddRating(ratingForm.SubmittedRating.Value);

            if (addRatingSuccess && ratingForm.SendActivity)
            {
                // Add a rating activity
                AddActivity(ratingForm.SubmittedRating.Value);
            }
            return(Redirect(UrlResolver.Current.GetUrl(ratingForm.CurrentPageLink)));
        }
Beispiel #2
0
        /// <summary>
        /// Validates the rating that was submitted.
        /// </summary>
        /// <param name="ratingForm">The rating form that was submitted.</param>
        private void ValidateSubmitRatingForm(RatingFormViewModel ratingForm)
        {
            string message = string.Empty;

            // Validate user is logged in
            if (!this.User.Identity.IsAuthenticated)
            {
                message = "Session timed out, you have to be logged in to submit your rating. Please login and try again.";
            }
            else
            {
                // Validate a rating was submitted
                if (!ratingForm.SubmittedRating.HasValue)
                {
                    message = "Please select a valid rating";
                }
                else
                {
                    // Retrieve and validate the page identifier of the page that was rated
                    this.pageId = this.pageRepository.GetPageId(ratingForm.CurrentPageLink);
                    if (String.IsNullOrWhiteSpace(this.pageId))
                    {
                        message = "The page id of this page could not be determined. Please try rating this page again.";
                    }
                    else
                    {
                        // Retrieve and validate the user identifier of the rater
                        this.userId = userRepository.GetUserId(this.User);
                        if (String.IsNullOrWhiteSpace(this.userId))
                        {
                            message = "There was an error identifying the logged in user. Please make sure you are logged in and try again.";
                        }
                    }
                }
            }
            AddMessage(MessageKey, new MessageViewModel(message, ErrorMessage));
        }