ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Customer/_CreateOrUpdate.TabRewardPoints.cshtml
@model CustomerModel

<div class="panel panel-default">
    <vc:admin-widget widget-zone="customer_details_reward_points_top" additional-data="Model" />
    <div class="panel-body">
        <div id="customer-rewardpoints-grid"></div>
    </div>
    <vc:admin-widget widget-zone="customer_details_reward_points_bottom" additional-data="Model" />
</div>

<script>
        $(document).ready(function () {
            $("#customer-rewardpoints-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("RewardPointsHistorySelect", "Customer", new { customerId = Model.Id }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors"
                    },
                    error: function(e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                pageable: {
                    refresh: true,
                    numeric: false,
                    previousNext: false,
                    info: false
                },
                editable: {
                    confirmation: false,
                    mode: "inline"
                },
                scrollable: false,
                columns: [{
                    field: "StoreName",
                    title: "@T("Admin.Customers.Customers.RewardPoints.Fields.Store")"
                },{
                    field: "Points",
                    title: "@T("Admin.Customers.Customers.RewardPoints.Fields.Points")"
                }, {
                    field: "PointsBalance",
                    title: "@T("Admin.Customers.Customers.RewardPoints.Fields.PointsBalance")"
                },{
                    field: "Message",
                    title: "@T("Admin.Customers.Customers.RewardPoints.Fields.Message")"
                },{
                    field: "CreatedOn",
                    title: "@T("Admin.Promotions.Campaigns.Fields.CreatedOn")",
                    width: 200,
                    type: "date",
                    format: "{0:G}"
                }]
            });
        });
</script>
<p>
    <strong> @T("Admin.Customers.Customers.RewardPoints.AddTitle")</strong>
</p>
<div class="form-horizontal">
    <div class="form-body">
        <div class="form-group">
            <admin-label asp-for="AddRewardPointsValue" />
            <div class="col-md-9 col-sm-9">
                <admin-input asp-for="AddRewardPointsValue" />
                <span asp-validation-for="AddRewardPointsValue"></span>
            </div>
        </div>
        <div class="form-group">
            <admin-label asp-for="AddRewardPointsMessage" />
            <div class="col-md-9 col-sm-9">
                <admin-input asp-for="AddRewardPointsMessage" />
                <span asp-validation-for="AddRewardPointsMessage"></span>
            </div>
        </div>
        <div class="form-group">
            <admin-label asp-for="AddRewardPointsStoreId" />
            <div class="col-md-9 col-sm-9">
                <admin-select asp-for="AddRewardPointsStoreId" asp-items="Model.RewardPointsAvailableStores" />
                <span asp-validation-for="AddRewardPointsStoreId"></span>
            </div>
        </div>
    </div>
    <div class="form-actions">
        <div class="offset-md-3">
            <input type="button" id="addRewardPoints" class="k-button" value="@T("Admin.Customers.Customers.RewardPoints.AddButton")" />
        </div>
    </div>
</div>
<script>
        $(document).ready(function () {
            $('#addRewardPoints').click(function () {
                var rewardPointsValue = $("#@Html.FieldIdFor(model => model.AddRewardPointsValue)").val();
                var rewardPointsMessage = $("#@Html.FieldIdFor(model => model.AddRewardPointsMessage)").val();
                var rewardPointsStoreId = $("#@Html.FieldIdFor(model => model.AddRewardPointsStoreId)").val();
                $('#addRewardPoints').attr('disabled', true);

                var postData = {
                    addRewardPointsValue: rewardPointsValue,
                    addRewardPointsMessage: rewardPointsMessage,
                    storeId: rewardPointsStoreId,
                    customerId: '@Model.Id'
                };
                addAntiForgeryToken(postData);

                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("RewardPointsHistoryAdd", "Customer"))",
                    data: postData,
                    success: function (data) {
                        var grid = $("#customer-rewardpoints-grid").data('kendoGrid');
                        grid.dataSource.read();
                        $('#addRewardPoints').attr('disabled', false);
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to add reward points.');
                        $('#addRewardPoints').attr('disabled', false);
                    }
                });
            });
        });
</script>