/// <summary>
 /// constructor
 /// </summary>
 /// <param name="src"></param>
 /// <param name="appUser"></param>
 /// <param name="poem"></param>
 /// <param name="mistake"></param>
 public RecitationViewModel(Recitation src, RAppUser appUser, GanjoorPoem poem, string mistake)
 {
     Id    = src.Id;
     Owner = new PublicRAppUser()
     {
         Id             = appUser.Id,
         Username       = appUser.UserName,
         Email          = appUser.Email,
         FirstName      = appUser.FirstName,
         SureName       = appUser.SureName,
         PhoneNumber    = appUser.PhoneNumber,
         RImageId       = appUser.RImageId,
         Status         = appUser.Status,
         NickName       = appUser.NickName,
         Website        = appUser.Website,
         Bio            = appUser.Bio,
         EmailConfirmed = appUser.EmailConfirmed
     };
     GanjoorAudioId           = src.GanjoorAudioId;
     GanjoorPostId            = src.GanjoorPostId;
     AudioOrder               = src.AudioOrder;
     FileNameWithoutExtension = src.FileNameWithoutExtension;
     SoundFilesFolder         = src.SoundFilesFolder;
     AudioTitle               = src.AudioTitle;
     AudioArtist              = src.AudioArtist;
     AudioArtistUrl           = src.AudioArtistUrl;
     AudioSrc         = src.AudioSrc;
     AudioSrcUrl      = src.AudioSrcUrl;
     LegacyAudioGuid  = src.LegacyAudioGuid;
     Mp3FileCheckSum  = src.Mp3FileCheckSum;
     Mp3SizeInBytes   = src.Mp3SizeInBytes;
     OggSizeInBytes   = src.OggSizeInBytes;
     LocalMp3FilePath = src.LocalMp3FilePath;
     LocalXmlFilePath = src.LocalXmlFilePath;
     ReviewStatus     = src.ReviewStatus;
     UploadDate       = src.UploadDate;
     FileLastUpdated  = src.FileLastUpdated;
     ReviewDate       = src.ReviewDate;
     if (poem != null)
     {
         PoemFullTitle = poem.FullTitle;
         PoemFullUrl   = poem.FullUrl;
     }
     AudioSyncStatus = src.AudioSyncStatus;
     if (string.IsNullOrEmpty(mistake))
     {
         ReviewMsg = src.ReviewMsg;
     }
     else
     {
         ReviewMsg = mistake;
     }
 }
Example #2
0
        private async Task _PreparePage()
        {
            using (HttpClient secureClient = new HttpClient())
            {
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}");

                    if (userInfoResponse.IsSuccessStatusCode)
                    {
                        PublicRAppUser userInfo = JsonConvert.DeserializeObject <PublicRAppUser>(await userInfoResponse.Content.ReadAsStringAsync());

                        UserInfo = new RegisterRAppUser()
                        {
                            Id          = userInfo.Id,
                            Username    = userInfo.Username,
                            FirstName   = userInfo.FirstName,
                            SureName    = userInfo.SureName,
                            NickName    = userInfo.NickName,
                            PhoneNumber = userInfo.PhoneNumber,
                            Email       = userInfo.Email,
                            Website     = userInfo.Website,
                            Bio         = userInfo.Bio,
                            RImageId    = userInfo.RImageId,
                            Status      = userInfo.Status,
                            IsAdmin     = false,
                            Password    = ""
                        };
                    }
                    else
                    {
                        LastError = await userInfoResponse.Content.ReadAsStringAsync();
                    }
                }
                else
                {
                    LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
                }
            }
        }
Example #3
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (string.IsNullOrEmpty(Request.Cookies["Token"]))
            {
                return(Redirect("/"));
            }

            LastError = "";
            using (HttpClient secureClient = new HttpClient())
                if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
                {
                    {
                        var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}");

                        if (userInfoResponse.IsSuccessStatusCode)
                        {
                            PublicRAppUser userInfo = JsonConvert.DeserializeObject <PublicRAppUser>(await userInfoResponse.Content.ReadAsStringAsync());

                            UserInfo = new RegisterRAppUser()
                            {
                                Id          = userInfo.Id,
                                Username    = userInfo.Username,
                                FirstName   = userInfo.FirstName,
                                SureName    = userInfo.SureName,
                                NickName    = userInfo.NickName,
                                PhoneNumber = userInfo.PhoneNumber,
                                Email       = userInfo.Email,
                                Website     = userInfo.Website,
                                Bio         = userInfo.Bio,
                                RImageId    = userInfo.RImageId,
                                Status      = userInfo.Status,
                                IsAdmin     = false,
                                Password    = ""
                            };
                        }
                        else
                        {
                            LastError = await userInfoResponse.Content.ReadAsStringAsync();
                        }

                        int pageNumber = 1;
                        if (!string.IsNullOrEmpty(Request.Query["page"]))
                        {
                            pageNumber = int.Parse(Request.Query["page"]);
                        }
                        var response = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/comments/mine?PageNumber={pageNumber}&PageSize=20");

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

                        Comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject <List <GanjoorCommentFullViewModel> >();

                        string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault();
                        if (!string.IsNullOrEmpty(paginnationMetadata))
                        {
                            PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject <PaginationMetadata>(paginnationMetadata);
                            PaginationLinks = new List <NameIdUrlImage>();
                            if (paginationMetadata.totalPages > 1)
                            {
                                if (paginationMetadata.currentPage > 3)
                                {
                                    PaginationLinks.Add
                                    (
                                        new NameIdUrlImage()
                                    {
                                        Name = "صفحهٔ اول",
                                        Url  = "/User/MyComments/?page=1"
                                    }
                                    );
                                }
                                for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++)
                                {
                                    if (i >= 1 && i <= paginationMetadata.totalPages)
                                    {
                                        if (i == paginationMetadata.currentPage)
                                        {
                                            PaginationLinks.Add
                                            (
                                                new NameIdUrlImage()
                                            {
                                                Name = i.ToPersianNumbers(),
                                            }
                                            );
                                        }
                                        else
                                        {
                                            PaginationLinks.Add
                                            (
                                                new NameIdUrlImage()
                                            {
                                                Name = i.ToPersianNumbers(),
                                                Url  = $"/User/MyComments/?page={i}"
                                            }
                                            );
                                        }
                                    }
                                }
                                if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
                                {
                                    PaginationLinks.Add
                                    (
                                        new NameIdUrlImage()
                                    {
                                        Name = "... ",
                                    }
                                    );

                                    PaginationLinks.Add
                                    (
                                        new NameIdUrlImage()
                                    {
                                        Name = "صفحهٔ آخر",
                                        Url  = $"/User/MyComments/?page={paginationMetadata.totalPages}"
                                    }
                                    );
                                }
                            }
                        }
                    }
                }
                else
                {
                    LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
                }
            return(Page());
        }