public void LoadReview()
 {
     if (Request.QueryString["ReviewID"] != null)
     {
         ProductReview r = new ProductReview();
         r = MyPage.MTApp.CatalogServices.ProductReviews.Find(ReviewID);
         if (r != null)
         {
             Product p = MyPage.MTApp.CatalogServices.Products.Find(r.ProductBvin);
             if (p != null)
             {
                 this.lblProductName.Text = p.ProductName;
             }
             else
             {
                 this.lblProductName.Text = "Unknown";
             }
             if (r.UserID != string.Empty)
             {
                 MerchantTribe.Commerce.Membership.CustomerAccount u = MyPage.MTApp.MembershipServices.Customers.Find(r.UserID);
                 if (u == null)
                 {
                     this.lblUserName.Text = "Anonymous";
                 }
                 else
                 {
                     this.lblUserName.Text = u.LastName + ", " + u.FirstName + " " + u.Email;
                 }
             }
             this.lblReviewDate.Text = r.ReviewDateForTimeZone(MyPage.MTApp.CurrentStore.Settings.TimeZone).ToString();
             this.chkApproved.Checked = r.Approved;
             this.KarmaField.Text = r.Karma.ToString();
             switch (r.Rating)
             {
                 case ProductReviewRating.ZeroStars:
                     lstRating.SelectedValue = "0";
                     break;
                 case ProductReviewRating.OneStar:
                     lstRating.SelectedValue = "1";
                     break;
                 case ProductReviewRating.TwoStars:
                     lstRating.SelectedValue = "2";
                     break;
                 case ProductReviewRating.ThreeStars:
                     lstRating.SelectedValue = "3";
                     break;
                 case ProductReviewRating.FourStars:
                     lstRating.SelectedValue = "4";
                     break;
                 case ProductReviewRating.FiveStars:
                     lstRating.SelectedValue = "5";
                     break;
             }
             this.DescriptionField.Text = r.Description;
         }
         r = null;
     }
 }
 protected void btnNew_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e)
 {
     ProductReview pr = new ProductReview();
     pr.Approved = true;
     pr.Description = "New Review";
     pr.UserID = SessionManager.GetCurrentUserId(MTApp.CurrentStore);
     pr.ReviewDateUtc = System.DateTime.UtcNow;
     pr.ProductBvin = Request.QueryString["ID"];
     //If Datalayer.ProductReviewMapper.SaveAsNew(pr) = True Then
     if (MTApp.CatalogServices.ProductReviews.Create(pr) == true)
     {
         Response.Redirect("Reviews_Edit.aspx?reviewID=" + pr.Bvin + "&DOC=1" + "&pid=" + Request.QueryString["id"]);
     }
 }
        public ActionResult Create()
        {
            string result = string.Empty;
            bool success = false;

            string productbvin = Request.Form["productbvin"];
            string newreview = Request.Form["newreview"];
            string rating = Request.Form["rating"];

            if (newreview.Trim().Length < 1)
            {
                result = "<div class=\"flash-message-warning\">Reviews can not be blank. Please enter your review and try again.</div>";
            }
            else
            {
                ProductReview rev = new ProductReview();
                rev.ProductBvin = productbvin;
                rev.Karma = 0;
                if (SessionManager.IsUserAuthenticated(MTApp) == true)
                {
                    rev.UserID = SessionManager.GetCurrentUserId(MTApp.CurrentStore);
                }
                else
                {
                    rev.UserID = "0";
                }

                rev.Description = HttpUtility.HtmlEncode(newreview.Trim());
                rev.ReviewDate = System.DateTime.Now;
                rev.Rating = (ProductReviewRating)int.Parse(rating);

                if (MTApp.CurrentStore.Settings.ProductReviewModerate == false)
                {
                    rev.Approved = true;
                }
                else
                {
                    rev.Approved = false;
                }

                MTApp.CatalogServices.ProductReviews.Create(rev);

                result = "<div class=\"flash-message-success\">Thank you for your review!</div>";
                success = true;
            }

            return Json(new { message = result, ok = success });
        }
        private Catalog.Product CreateBlueBracelet()
        {
            Catalog.Product p = new Product();
            p.Sku = "SAMPLE001";
            p.ProductName = "Blue Bracelet";
            p.AllowReviews = true;
            p.Featured = true;
            p.ImageFileSmall = "BraceletBlue.png";
            p.ImageFileSmallAlternateText = "Blue Bracelet SAMPLE001";
            p.InventoryMode = ProductInventoryMode.AlwayInStock;
            p.Keywords = "bracelett";
            p.ListPrice = 0;
            p.LongDescription = "An incredible blue bracelet sample product. This item is not actually for sale. It is a sample product to demonstrate how your store may look with products loaded";
            p.MetaDescription = "Sample Blue Bracelet for Demonstration";
            p.MetaKeywords = "Blue,Bracelet,Sample,Demo";
            p.MetaTitle = "Sample Blue Bracelet";
            p.SitePrice = 42.95m;
            p.Status = ProductStatus.Active;
            p.UrlSlug = "blue-bracelet";
            p.Tabs.Add(new ProductDescriptionTab() { TabTitle = "Sustainability", HtmlData = "<p>All of our jewelry products are recycled and made in sustainable eco-friendly environments</p>" });
            CatalogServices.ProductsCreateWithInventory(p, true);

            Storage.DiskStorage.CopyDemoProductImage(p.StoreId, p.Bvin, p.ImageFileSmall);

            // Create Review
            ProductReview review = new ProductReview();
            review.Approved = true;
            review.Description = "This is a great bracelet. I would recommend it to anyone who appreciates sample products. Easy to wear!";
            review.ProductBvin = p.Bvin;
            review.Rating = ProductReviewRating.FourStars;
            CatalogServices.ProductReviews.Create(review);

            return p;
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse<ProductReviewDTO> response = new ApiResponse<ProductReviewDTO>();

            ProductReviewDTO postedItem = null;
            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson<ProductReviewDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return MerchantTribe.Web.Json.ObjectToJson(response);
            }

            ProductReview item = new ProductReview();
            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                if (MTApp.CatalogServices.ProductReviews.Create(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                MTApp.CatalogServices.ProductReviews.Update(item);
            }
            ProductReview resultItem = MTApp.CatalogServices.ProductReviews.Find(bvin);
            if (resultItem != null) response.Content = resultItem.ToDto();

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return data;
        }
        protected void btnOK_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e)
        {
            try
            {
                if (Request.QueryString["ReviewID"] != null)
                {
                    ProductReview r = new ProductReview();
                    r = MyPage.MTApp.CatalogServices.ProductReviews.Find(ReviewID);
                    if (r != null)
                    {
                        r.Approved = this.chkApproved.Checked;
                        r.Karma = int.Parse(this.KarmaField.Text.Trim());
                        r.Rating = (ProductReviewRating)int.Parse(this.lstRating.SelectedValue);
                        r.Description = this.DescriptionField.Text.Trim();
                    }
                    MyPage.MTApp.CatalogServices.ProductReviews.Update(r);
                    r = null;

                    if (Request.QueryString["pid"] == null)
                    {
                        Response.Redirect("ReviewsToModerate.aspx");
                    }
                    else
                    {
                        Response.Redirect("Products_Edit_Reviews.aspx?id=" + Request.QueryString["pid"]);
                    }
                }
            }
            catch (System.Exception ex)
            {
                EventLog.LogEvent(ex);
            }
        }