ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Views/Newsletter/NewsletterCategory.cshtml
@model NewsletterCategoryModel
@inject IWebHelper webHelper
@{ 
    var storeLocation = webHelper.GetStoreLocation();
}
<div class="newsletter-category">
    <div class="newsletter-category-title pb-3">
        <h5>@T("NewsletterCategory.Title")</h5>
    </div>
    <form id="newsletter-category-method-form" action="" >
        <input asp-for="NewsletterEmailId" type="hidden" />
        <div class="newsletter-category-body form-group">
                @foreach (var category in Model.NewsletterCategories)
                {
                    <label for="Category_@(category.Id)" class="custom-control custom-checkbox col-12">
                        <input id="Category_@(category.Id)"  name="Category_@(category.Id)" type="checkbox" class="custom-control-input" @(category.Selected ? "checked": "")>
                        <span class="custom-control-label"></span>
                        <span class="custom-control-description">@category.Name</span>
                    </label>
                    <div>
                        @Html.Raw(category.Description)
                    </div>
                }
            <div class="newsletter-category-save pt-1 pb-1">
                <input type="button" value="@T("NewsletterCategory.Options.Save")" id="newsletter-category-button" class="btn btn-success newsletter-subscribe-button" />
            </div>
        </div>
    </form>

    <script asp-location="Footer">
        function newsletter_subscribe_category() {
            $.ajax({
                cache: false,
                type: "POST",
                url: "@(Url.RouteUrl("SubscribeNewsletterCategory"))",
                data: $('#newsletter-category-method-form').serialize(),
                success: function(data) {
                    if (data.Success) {
                        var magnificPopup = $.magnificPopup.instance;
                        magnificPopup.close();
                    } else {
                        alert(data.Message);
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert('Failed to assignt to categories.');
                    var magnificPopup = $.magnificPopup.instance;
                    magnificPopup.close();
                }
            });
        }
        $(document).ready(function () {
            $('#newsletter-category-button').click(function () {
                newsletter_subscribe_category();
            });

        });
    </script>

</div>
