ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Views/Product/_ProductReviewHelpfulness.cshtml
@model ProductReviewHelpfulnessModel
<div class="product-review-helpfulness d-inline-flex justify-content-end align-items-center">
    <span class="question">@T("Reviews.Helpfulness.WasHelpful?")</span>
    <span class="vote-options btn-group">
        <span id="vote-yes-@(Model.ProductReviewId)" class="btn btn-sm btn-outline vote">👍</span>
        <span id="vote-no-@(Model.ProductReviewId)" class="btn btn-sm btn-outline vote">👎</span>
    </span>
    <span class="vote-stats">
        (<span id="helpfulness-vote-yes-@(Model.ProductReviewId)">@(Model.HelpfulYesTotal)</span>/<span id="helpfulness-vote-no-@(Model.ProductReviewId)">@(Model.HelpfulNoTotal)</span>)
    </span>
    <span id="helpfulness-vote-result-@(Model.ProductReviewId)" class="result"></span>

    
    <script asp-location="Footer">
        $(document).ready(function () {
            $('#vote-yes-@(Model.ProductReviewId)').click(function () {
                setProductReviewHelpfulness@(Model.ProductReviewId)('true');
            });
            $('#vote-no-@(Model.ProductReviewId)').click(function () {
                setProductReviewHelpfulness@(Model.ProductReviewId)('false');
            });
        });

        function setProductReviewHelpfulness@(Model.ProductReviewId)(wasHelpful){
                $.ajax({
                    cache: false,
                    type: "POST",
                    url: "@(Url.RouteUrl("SetProductReviewHelpfulness"))",
                    data: { "productReviewId": '@(Model.ProductReviewId)', "productId": '@(Model.ProductId)' ,"washelpful": wasHelpful },
                    success: function (data) {
                         $("#helpfulness-vote-yes-@(Model.ProductReviewId)").html(data.TotalYes);
                         $("#helpfulness-vote-no-@(Model.ProductReviewId)").html(data.TotalNo);
                         $("#helpfulness-vote-result-@(Model.ProductReviewId)").html(data.Result);
                                                  
                         $('#helpfulness-vote-result-@(Model.ProductReviewId)').fadeIn("slow").delay(1000).fadeOut("slow");
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to vote. Please refresh the page and try one more time.');
                    }  
                });
        }
    </script>
</div>
