public async Task <IActionResult> ReportErrorAsync([FromBody] RecitationErrorReportViewModel report)
        {
            if (ReadOnlyMode)
            {
                return(BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید."));
            }

            Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            var  res            = await _audioService.ReportErrorAsync(loggedOnUserId, report);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }
            return(Ok(res.Result));
        }
        public async Task <IActionResult> AddReportToTheApprovedMistakesAsync([FromBody] RecitationErrorReportViewModel report)
        {
            if (ReadOnlyMode)
            {
                return(BadRequest("سایت به دلایل فنی مثل انتقال سرور موقتاً در حالت فقط خواندنی قرار دارد. لطفاً ساعاتی دیگر مجدداً تلاش کنید."));
            }
            RServiceResult <bool> res = await _audioService.AddReportToTheApprovedMistakesAsync(report);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }
            if (!res.Result)
            {
                return(NotFound());
            }
            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> OnGetAsync()
        {
            PostSuccess    = false;
            LastError      = "";
            LoggedIn       = !string.IsNullOrEmpty(Request.Cookies["Token"]);
            RecitationInfo = "";

            Report = new RecitationErrorReportViewModel()
            {
                ReasonText            = "",
                NumberOfLinesAffected = 1,
                CoupletIndex          = -1,
            };

            if (!string.IsNullOrEmpty(Request.Query["a"]))
            {
                Report.RecitationId = int.Parse(Request.Query["a"]);
                var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/published/{Report.RecitationId}");

                if (!response.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync());
                }
                else
                {
                    var recitation = JsonConvert.DeserializeObject <PublicRecitationViewModel>(await response.Content.ReadAsStringAsync());
                    RecitationInfo = $"{recitation.AudioTitle} به خوانش {recitation.AudioArtist}";

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

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

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

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


                    int    coupetIndex = -1;
                    string coupletText = "";
                    List <Tuple <int, string> > couplets = new List <Tuple <int, string> >();
                    couplets.Add(new Tuple <int, string>(-1, "*"));
                    foreach (var verse in pageInformation.Poem.Verses)
                    {
                        if (verse.CoupletIndex != null && verse.CoupletIndex != coupetIndex && verse.CoupletIndex >= 0)
                        {
                            if (!string.IsNullOrEmpty(coupletText))
                            {
                                couplets.Add(new Tuple <int, string>(coupetIndex, coupletText));
                            }
                            coupetIndex = (int)verse.CoupletIndex;
                            coupletText = "";
                        }
                        if (!string.IsNullOrEmpty(coupletText))
                        {
                            coupletText += " ";
                        }
                        coupletText += verse.Text;
                    }

                    if (!string.IsNullOrEmpty(coupletText))
                    {
                        couplets.Add(new Tuple <int, string>(coupetIndex, coupletText));
                    }

                    Couplets = couplets.ToArray();
                }
            }
            else
            {
                Report.RecitationId = 0;
            }

            return(Page());
        }