Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync()
        {
            LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]);



            if (!string.IsNullOrEmpty(Request.Query["p"]))
            {
                var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poet?url=/{Request.Query["p"]}");

                if (!response.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync());
                    return(Page());
                }
                Poet          = JObject.Parse(await response.Content.ReadAsStringAsync()).ToObject <GanjoorPoetCompleteViewModel>().Poet;
                Poet.ImageUrl = $"{APIRoot.InternetUrl}{Poet.ImageUrl}";

                var responseLines = await _httpClient.GetAsync($"{APIRoot.Url}/api/poetspecs/poet/{Poet.Id}");

                if (!responseLines.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await responseLines.Content.ReadAsStringAsync());
                    return(Page());
                }
                SpecLines = JArray.Parse(await responseLines.Content.ReadAsStringAsync()).ToObject <List <GanjoorPoetSuggestedSpecLineViewModel> >();

                var responsePhotos = await _httpClient.GetAsync($"{APIRoot.Url}/api/poetphotos/poet/{Poet.Id}");

                if (!responsePhotos.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await responsePhotos.Content.ReadAsStringAsync());
                    return(Page());
                }
                Photos = JArray.Parse(await responsePhotos.Content.ReadAsStringAsync()).ToObject <List <GanjoorPoetSuggestedPictureViewModel> >();

                foreach (var photo in Photos)
                {
                    photo.ImageUrl = $"{APIRoot.InternetUrl}/{photo.ImageUrl}";
                }

                if (LoggedIn)
                {
                    await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);

                    ModeratePoetPhotos = ViewData.ContainsKey($"{RMuseumSecurableItem.GanjoorEntityShortName}-{RMuseumSecurableItem.ModeratePoetPhotos}");
                }
            }
            else
            {
                Poets = await _PreparePoets();
            }

            ViewData["Title"] = Poet == null ? "پیشنهاد تصویر برای شاعران" : $"پیشنهاد تصویر برای {Poet.Nickname}";

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

            LastMessage = "";
            await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);

            if (!ViewData.ContainsKey($"{RMuseumSecurableItem.FAQEntityShortName}-{RMuseumSecurableItem.ModerateOperationShortName}"))
            {
                LastMessage = "شما به این بخش دسترسی ندارید.";
                return(Page());
            }

            CatId = 0;

            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/faq/cat/secure");

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

                    Categories = JsonConvert.DeserializeObject <FAQCategory[]>(await response.Content.ReadAsStringAsync());

                    if (Categories.Length > 0)
                    {
                        CatId    = string.IsNullOrEmpty(Request.Query["catId"]) ? Categories[0].Id : int.Parse(Request.Query["catId"]);
                        response = await secureClient.GetAsync($"{APIRoot.Url}/api/faq/cat/items/secure?catId={CatId}");

                        if (!response.IsSuccessStatusCode)
                        {
                            return(new BadRequestObjectResult(JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync())));
                        }

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

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

            LastMessage = "";
            await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);

            if (!ViewData.ContainsKey($"{RMuseumSecurableItem.GanjoorEntityShortName}-{RMuseumSecurableItem.Translations}"))
            {
                LastMessage = "شما به این بخش دسترسی ندارید.";
                return(Page());
            }

            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/languages");

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

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


            return(Page());
        }
Exemplo n.º 4
0
        /// <summary>
        /// get
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAsync()
        {
            if (string.IsNullOrEmpty(Request.Cookies["Token"]))
            {
                return(Redirect("/"));
            }

            FatalError = "";
            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);

                    if (!ViewData.ContainsKey($"{RMuseumSecurableItem.GanjoorEntityShortName}-{RMuseumSecurableItem.Translations}"))
                    {
                        FatalError = "حساب کاربری شما به این بخش دسترسی ندارد.";
                        return(Page());
                    }

                    int poemId = int.Parse(Request.Query["id"]);

                    int transId = string.IsNullOrEmpty(Request.Query["t"]) ? -1 : int.Parse(Request.Query["t"]);

                    int langId = string.IsNullOrEmpty(Request.Query["lang"]) ? -1 : int.Parse(Request.Query["lang"]);

                    HttpResponseMessage response = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/poem/{poemId}/language/{langId}");

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

                    var translations = JsonConvert.DeserializeObject <GanjoorPoemTranslationViewModel[]>(await response.Content.ReadAsStringAsync());

                    var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}");

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

                    if (transId != -1)
                    {
                        Translation = translations.Where(t => t.Id == transId).Single();
                        langId      = Translation.Language.Id;
                    }

                    if (langId == -1)
                    {
                        var lastLangResp = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/user/lastlanguage");

                        if (response.StatusCode != HttpStatusCode.NotFound)
                        {
                            var lang = JsonConvert.DeserializeObject <GanjoorLanguage>(await lastLangResp.Content.ReadAsStringAsync());
                            if (lang != null)
                            {
                                langId = lang.Id;
                            }
                        }
                    }

                    if (langId != -1 && Translation == null)
                    {
                        Translations = translations;
                        foreach (var translation in translations)
                        {
                            if (translation.ContributerId == UserInfo.Id && langId == translation.Language.Id)
                            {
                                Translation = translation;
                                break;
                            }
                        }
                    }
                    else if (translations.Length > 0 && Translation == null)
                    {
                        foreach (var translation in translations)
                        {
                            if (translation.ContributerId == UserInfo.Id)
                            {
                                Translation = translation;
                                langId      = Translation.Language.Id;
                                break;
                            }
                        }
                        if (langId == -1)
                        {
                            Translation = translations[0];
                            langId      = Translation.Language.Id;
                        }
                    }



                    HttpResponseMessage responseLanguages = await secureClient.GetAsync($"{APIRoot.Url}/api/translations/languages");

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


                    Languages = JsonConvert.DeserializeObject <GanjoorLanguage[]>(await responseLanguages.Content.ReadAsStringAsync());

                    if (Languages.Length == 0)
                    {
                        FatalError = "<a role=\"button\" target=\"_blank\" href=\"/User/Languages\" class=\"actionlink\">معرفی زبان‌ها و نویسش‌ها</a>";
                        return(Page());
                    }

                    if (langId == -1)
                    {
                        langId = Languages[0].Id;
                    }


                    var pageUrlResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={poemId}");

                    if (!pageUrlResponse.IsSuccessStatusCode)
                    {
                        FatalError = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());
                        return(Page());
                    }
                    var pageUrl = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());

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

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

                    if (Translation == null)
                    {
                        Translation = new GanjoorPoemTranslationViewModel()
                        {
                            Language        = Languages.Where(l => l.Id == langId).Single(),
                            PoemId          = PageInformation.Id,
                            Title           = "",
                            Published       = false,
                            Description     = "",
                            ContributerName = UserInfo.NickName == null?UserInfo.Id.ToString() : UserInfo.NickName,
                                                  TranslatedVerses = PageInformation.Poem.Verses.Select(v =>
                                                                                                        new GanjoorVerseTranslationViewModel()
                            {
                                Verse = v,
                                TText = ""
                            }
                                                                                                        ).ToArray()
                        };

                        Translations = new GanjoorPoemTranslationViewModel[] { Translation };
                    }

                    if (langId != -1)
                    {
                        Translations = translations.Where(t => t.Language.Id == langId).ToArray();
                    }
                }
                else
                {
                    FatalError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
                }
            }
            return(Page());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync()
        {
            ErrorMessage = "";

            CanTranslate = false;
            if (!string.IsNullOrEmpty(Request.Cookies["Token"]))
            {
                await GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);

                if (ViewData.ContainsKey($"{RMuseumSecurableItem.GanjoorEntityShortName}-{RMuseumSecurableItem.Translations}"))
                {
                    CanTranslate = true;
                }
            }



            PoemId = int.Parse(Request.Query["p"]);

            ViewData["GoogleAnalyticsCode"] = _configuration["GoogleAnalyticsCode"];

            HttpResponseMessage responseLanguages = await _httpClient.GetAsync($"{APIRoot.Url}/api/translations/languages");

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

            var allLanguages = JsonConvert.DeserializeObject <GanjoorLanguage[]>(await responseLanguages.Content.ReadAsStringAsync());

            HttpResponseMessage response = await _httpClient.GetAsync($"{APIRoot.Url}/api/translations/poem/{PoemId}/published");

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

            Translations = JsonConvert.DeserializeObject <GanjoorPoemTranslationViewModel[]>(await response.Content.ReadAsStringAsync());

            LanguageId = string.IsNullOrEmpty(Request.Query["lang"]) ? -1 : int.Parse(Request.Query["lang"]);

            List <GanjoorLanguage> poemLanguages = new List <GanjoorLanguage>();

            foreach (var lang in allLanguages)
            {
                if (Translations.Where(t => t.Language.Id == lang.Id).FirstOrDefault() != null)
                {
                    poemLanguages.Add(lang);
                }
            }
            if (LanguageId != -1)
            {
                if (!poemLanguages.Where(l => l.Id == LanguageId).Any())
                {
                    poemLanguages.Add(allLanguages.Where(l => l.Id == LanguageId).Single());
                }
            }
            Languages = poemLanguages.ToArray();

            if (LanguageId != -1)
            {
                Translations = Translations.Where(t => t.Language.Id == LanguageId).ToArray();
            }

            Translation = Translations.Length > 0 ? Translations[0] : null;

            if (Translation != null)
            {
                LanguageId = Translation.Language.Id;
            }
            var responsePoem = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{PoemId}?verseDetails=true&catInfo=true&rhymes=false&recitations=false&images=false&songs=false&comments=false&navigation=true");

            if (!responsePoem.IsSuccessStatusCode)
            {
                ErrorMessage = JsonConvert.DeserializeObject <string>(await responsePoem.Content.ReadAsStringAsync());
                return(Page());
            }
            Poem = JsonConvert.DeserializeObject <GanjoorPoemCompleteViewModel>(await responsePoem.Content.ReadAsStringAsync());
            return(Page());
        }