protected void btnSave_Click(object sender, EventArgs e) { string sRating = ddlRating.SelectedValue; if (!String.IsNullOrEmpty(sRating)) { //if the selection is null for some reason //default it. int rating = int.Parse(sRating); //add the review string review = Utility.StripHTML(txtReview.Text); string title = Utility.StripHTML(txtTitle.Text); try { string thisUser = Utility.GetUserName(); ProductReview rev = new ProductReview(); rev.ProductID = productID; rev.AuthorName = thisUser; rev.Body = review; rev.IsApproved = false; rev.PostDate = DateTime.UtcNow; rev.Rating = rating; rev.Title = title; rev.Save(thisUser); ResultMessage1.ShowSuccess("Review Saved!"); } catch (Exception x) { ResultMessage1.ShowFail("Oops! There was an error and your review was not saved: " + x.Message); } } ToggleEditor(false); }
protected void GoButton_Click(object sender, EventArgs e) { List <int> reviewIds = GetSelectedReviewIds(); if (reviewIds.Count > 0) { if (ReviewAction.SelectedValue == "Delete") { foreach (int reviewId in reviewIds) { ProductReviewDataSource.Delete(reviewId); } } else if ((ReviewAction.SelectedValue == "Approve") || (ReviewAction.SelectedValue == "Disapprove")) { bool approved = (ReviewAction.SelectedValue == "Approve"); foreach (int reviewId in reviewIds) { ProductReview review = ProductReviewDataSource.Load(reviewId); review.IsApproved = approved; review.Save(); } } ReviewGrid.DataBind(); } ReviewAction.SelectedIndex = 0; }
private void Save() { //FIRST UPDATE THE PROFILE ReviewerProfile profile = _ProductReview.ReviewerProfile; profile.Email = ReviewerEmail.Text; profile.DisplayName = ReviewerName.Text; profile.Location = ReviewerLocation.Text; profile.Save(); //NEXT UPDATE THE REVIEW _ProductReview.IsApproved = Approved.Checked; _ProductReview.ReviewTitle = ReviewTitle.Text; _ProductReview.ReviewBody = ReviewBody.Text; _ProductReview.Save(); SuccessMessage.Text = string.Format(SuccessMessage.Text, LocaleHelper.LocalNow); SuccessMessage.Visible = true; }
private bool SaveReview() { // SAVE REVIEWER PROFILE User user = AbleContext.Current.User; //MAKE SURE ANONYMOUS USER DOES NOT TRY TO USE REGISTERED USER EMAIL if (user.IsAnonymous) { IList <User> users = UserDataSource.LoadForEmail(Email.Text); if (users.Count > 0) { CustomValidator invalidEmail = new CustomValidator(); invalidEmail.Text = "*"; invalidEmail.ErrorMessage = "Your email address is already registered. You must log in to post the review."; invalidEmail.IsValid = false; invalidEmail.ValidationGroup = "ProductReviewForm"; phEmailValidators.Controls.Add(invalidEmail); return(false); } user.Save(); } _Profile = user.ReviewerProfile; // TRY TO LOAD PROFILE BY EMAIL if (_Profile == null) { _Profile = ReviewerProfileDataSource.LoadForEmail(Email.Text); if (_Profile != null) { if (_ProductReview == null) { _ProductReview = ProductReviewDataSource.LoadForProductAndReviewerProfile(_ProductId, _Profile.Id); } // ATTEMPT TO SUBMIT A 2ND REVIEW FOR THIS PRODUCT BY AN ANNONYMOUS USER if (_ProductReview != null && String.IsNullOrEmpty(Request.Form[OverwriteReviewButton.UniqueID])) { // WARN THE USER THAT A REVIEW IS ALREADY SUBMITTED BY SAME EMAIL ADDRESS CustomValidator reviewAlreadySubmitted = new CustomValidator(); reviewAlreadySubmitted.Text = "*"; reviewAlreadySubmitted.ErrorMessage = "You have already submitted a review for this product, do you want to overwrite your previous review?"; reviewAlreadySubmitted.IsValid = false; reviewAlreadySubmitted.ValidationGroup = "ProductReviewForm"; phEmailValidators.Controls.Add(reviewAlreadySubmitted); OverwriteReviewButton.Visible = true; SubmitReviewButton.Visible = false; return(false); } } } if (_Profile == null) { _Profile = new ReviewerProfile(); } _Profile.Email = ((user.IsAnonymous && String.IsNullOrEmpty(GetUserEmail())) ? Email.Text : GetUserEmail()); _Profile.DisplayName = StringHelper.StripHtml(Name.Text, true); _Profile.Location = StringHelper.StripHtml(Location.Text, true); _Profile.Save(); //IF PROFILE IS NULL, AN ERROR OCCURRED VALIDATING THE EMAIL if (_Profile != null) { //EITHER LOAD THE EXISTING REVIEW OR CREATE NEW if (_ProductReview == null) { _ProductReview = ProductReviewDataSource.LoadForProductAndReviewerProfile(_ProductId, _Profile.Id); } if (_ProductReview == null) { _ProductReview = new ProductReview(); } _ProductReview.ReviewerProfile = _Profile; _ProductReview.Product = _Product; _ProductReview.ReviewDate = LocaleHelper.LocalNow; _ProductReview.Rating = AlwaysConvert.ToByte(Rating.SelectedValue); _ProductReview.ReviewTitle = StringHelper.StripHtml(ReviewTitle.Text, true); _ProductReview.ReviewBody = StringHelper.StripHtml(ReviewBody.Text, true); _ProductReview.Save(AbleContext.Current.User, true, true); return(true); } return(false); }