public async Task <IActionResult> OnGetAsync()
        {
            if (string.IsNullOrEmpty(Request.Cookies["Token"]))
            {
                return(Redirect("/"));
            }


            LastMessage = "";

            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/oldversion/{Request.Query["id"]}");

                    if (!response.IsSuccessStatusCode)
                    {
                        LastMessage = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync());
                        return(Page());
                    }

                    EarlierVersion = JsonConvert.DeserializeObject <GanjoorModifyPageViewModel>(await response.Content.ReadAsStringAsync());
                }
                else
                {
                    LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
                }
            }

            return(Page());
        }
        private async Task <bool> PreparePage()
        {
            var rhythmResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/rhythms");

            if (!rhythmResponse.IsSuccessStatusCode)
            {
                LastMessage = JsonConvert.DeserializeObject <string>(await rhythmResponse.Content.ReadAsStringAsync());
                return(false);
            }

            Rhythms = JsonConvert.DeserializeObject <GanjoorMetre[]>(await rhythmResponse.Content.ReadAsStringAsync());

            var pageUrlResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["id"]}");

            if (!pageUrlResponse.IsSuccessStatusCode)
            {
                LastMessage = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());
                return(false);
            }

            var pageUrl = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());

            var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={pageUrl}");

            if (!pageQuery.IsSuccessStatusCode)
            {
                LastMessage = JsonConvert.DeserializeObject <string>(await pageQuery.Content.ReadAsStringAsync());
                return(false);
            }
            PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject <GanjoorPageCompleteViewModel>();

            if (PageInformation.Poem != null)
            {
                DefaultHtmlText = _DefHtmlText(PageInformation.Poem.Verses);
            }

            ModifyModel = new GanjoorModifyPageViewModel()
            {
                Title                = PageInformation.Title,
                UrlSlug              = PageInformation.UrlSlug,
                HtmlText             = PageInformation.HtmlText,
                Note                 = "",
                SourceName           = PageInformation.Poem == null ? null : PageInformation.Poem.SourceName,
                SourceUrlSlug        = PageInformation.Poem == null ? null : PageInformation.Poem.SourceUrlSlug,
                OldTag               = PageInformation.Poem == null ? null : PageInformation.Poem.OldTag,
                OldTagPageUrl        = PageInformation.Poem == null ? null : PageInformation.Poem.OldTagPageUrl,
                RhymeLetters         = PageInformation.Poem == null ? null : PageInformation.Poem.RhymeLetters,
                Rhythm               = PageInformation.Poem == null ? null : PageInformation.Poem.GanjoorMetre == null ? null : PageInformation.Poem.GanjoorMetre.Rhythm,
                NoIndex              = PageInformation.NoIndex,
                RedirectFromFullUrl  = PageInformation.RedirectFromFullUrl,
                Language             = PageInformation.Poem == null ? null : PageInformation.Poem.Language,
                MixedModeOrder       = PageInformation.Poem == null ? (PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.MixedModeOrder : 0) : PageInformation.Poem.MixedModeOrder,
                Published            = PageInformation.Poem == null ? (PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.Published : true) : PageInformation.Poem.Published,
                TableOfContentsStyle = PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.TableOfContentsStyle : GanjoorTOC.Analyse,
                CatType              = PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.CatType : GanjoorCatType.Default,
                Description          = PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.Description : "",
                DescriptionHtml      = PageInformation.GanjoorPageType == GanjoorPageType.CatPage ? PageInformation.PoetOrCat.Cat.DescriptionHtml : ""
            };
            return(true);
        }
        public async Task <IActionResult> OnPostAsync(GanjoorModifyPageViewModel ModifyModel)
        {
            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    var response = await secureClient.PutAsync($"{APIRoot.Url}/api/ganjoor/page/{Request.Query["id"]}", new StringContent(JsonConvert.SerializeObject(ModifyModel), Encoding.UTF8, "application/json"));

                    if (!response.IsSuccessStatusCode)
                    {
                        LastMessage = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync());
                    }
                    else
                    {
                        return(Redirect($"/Admin/ModifyPage?id={Request.Query["id"]}&edit=true"));
                    }
                }
                else
                {
                    LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
                }
            }
            return(Page());
        }