Пример #1
0
        private bool TryCreateReview(IProductDataAdapter productDataAdapter, string title, string content, double rating,
                                     int maximumRatingValue, string reviewerName, string reviewerLocation, string reviewerEmail, bool recommend)
        {
            if (string.IsNullOrWhiteSpace(reviewerName))
            {
                ModelState.AddModelError("reviewerName", ResourceManager.GetString("Required_Nick_Name"));
            }

            if (!Request.IsAuthenticated)
            {
                if (string.IsNullOrWhiteSpace(reviewerEmail))
                {
                    ModelState.AddModelError("reviewerEmail", ResourceManager.GetString("Required_Email"));
                }
            }

            if (string.IsNullOrWhiteSpace(title))
            {
                ModelState.AddModelError("title", ResourceManager.GetString("Required_Title"));
            }

            if (rating < 1)
            {
                ModelState.AddModelError("rating", ResourceManager.GetString("Required_Rating"));
            }

            if (!ModelState.IsValid)
            {
                return(false);
            }

            productDataAdapter.CreateReview(title, content, rating, maximumRatingValue, reviewerName, reviewerLocation, reviewerEmail, recommend);

            return(true);
        }
Пример #2
0
        private bool TryCreateReview(IProductDataAdapter productDataAdapter, string title, string content, double rating,
                                     int maximumRatingValue, string reviewerName, string reviewerLocation, string reviewerEmail, bool recommend)
        {
            if (string.IsNullOrWhiteSpace(reviewerName))
            {
                ModelState.AddModelError("reviewerName", "Your nickname is required.");
            }

            if (!Request.IsAuthenticated)
            {
                if (string.IsNullOrWhiteSpace(reviewerEmail))
                {
                    ModelState.AddModelError("reviewerEmail", "E-mail is required; it will not be displayed.");
                }
            }

            if (string.IsNullOrWhiteSpace(title))
            {
                ModelState.AddModelError("title", "Title is required.");
            }

            if (rating < 1)
            {
                ModelState.AddModelError("rating", "Rating is required.");
            }

            if (!ModelState.IsValid)
            {
                return(false);
            }

            productDataAdapter.CreateReview(title, content, rating, maximumRatingValue, reviewerName, reviewerLocation, reviewerEmail, recommend);

            return(true);
        }