コード例 #1
0
        public async Task <IActionResult> DeletePage(string WebcomicName, int PageNumber, ComicArchiveViewModel model)
        {
            _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            using (var _http = new HttpClient(_clientHandler))
            {
                var response = await _http.GetAsync(_webcomicsUri);

                if (response.IsSuccessStatusCode)
                {
                    var ComicBooks = JsonConvert.DeserializeObject <List <ComicBookModel> >(await response.Content.ReadAsStringAsync());
                    if (ComicBooks.FirstOrDefault(c => c.Title == WebcomicName) != null)
                    {
                        ComicBookViewModel webcomic = new ComicBookViewModel(ComicBooks.FirstOrDefault(c => c.Title == WebcomicName));

                        if (User.Identity.Name != webcomic.Author)
                        {
                            //Impossible via in-application links; user is hacking. Back to main page,
                            //for lack of a more severe punishment.
                            return(View("MainArchiveView", new MainArchiveViewModel(ComicBooks)));
                        }

                        if (webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber) != null)
                        {
                            ComicPageModel page          = webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber);
                            var            stringData    = JsonConvert.SerializeObject(page);
                            var            stringContent = new StringContent(stringData, UnicodeEncoding.UTF8, "application/json");
                            var            request       = new HttpRequestMessage {
                                Method     = HttpMethod.Delete,
                                RequestUri = new Uri(_pagesUri),
                                Content    = stringContent
                            };
                            var response2 = await _http.SendAsync(request);

                            if (response2.IsSuccessStatusCode)
                            {
                                //switch to AuthorController.AuthorHome once that's up and running
                                //return View("ComicArchiveView", new ComicArchiveViewModel(new ComicBookModel(webcomic)));
                                return(await(new AuthorController()).AuthorHome());
                            }
                            return(View("Error", new ErrorViewModel {
                                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                            }));
                        }
                        //return View("ComicArchiveView", model);
                        //There is no page to delete; back to the archive with you!
                        //switch to AuthorController.AuthorHome once that's up and running
                        return(await(new AuthorController()).AuthorHome());
                    }
                    return(View("MainArchiveView", new MainArchiveViewModel(ComicBooks)));
                    //There is no such webcomic; back to the archive with you!
                    //Impossible via in-application links.
                }
            }
            return(View("Error", new ErrorViewModel {
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            }));
        }
コード例 #2
0
        public async Task <IActionResult> GetUpdatePage(string WebcomicName, int PageNumber)
        {
            _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            using (var _http = new HttpClient(_clientHandler))
            {
                var response = await _http.GetAsync(_webcomicsUri);

                if (response.IsSuccessStatusCode)
                {
                    var ComicBooks = JsonConvert.DeserializeObject <List <ComicBookModel> >(await response.Content.ReadAsStringAsync());

                    if (ComicBooks.FirstOrDefault(c => c.Title == WebcomicName) != null)
                    {
                        ComicBookModel webcomic = ComicBooks.FirstOrDefault(c => c.Title == WebcomicName);

                        if (User.Identity.Name != webcomic.Author)
                        {
                            //Impossible via in-application links; user is hacking. Back to main page,
                            //for lack of a more severe punishment.
                            return(View("MainArchiveView", new MainArchiveViewModel(ComicBooks)));
                        }

                        if (webcomic.ComicPages == null || webcomic.ComicPages.Count == 0)
                        {
                            //return View("ComicArchiveView", new ComicArchiveViewModel(webcomic));
                            //There is no page to update; back to the archive with you
                            //Change to AuthorHome once that's up and running.
                            return(await(new AuthorController()).AuthorHome());
                        }

                        webcomic.ComicPages = webcomic.ComicPages.OrderBy(p => p.PageNumber).ToList();
                        if (webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber) != null)
                        {
                            ComicPageModel page = webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber);
                            page.ComicBook = webcomic;
                            ComicPageViewModel pageview = new ComicPageViewModel(page);
                            return(View("UpdatePageView", pageview));
                        }
                        return(View("ComicArchiveView", new ComicArchiveViewModel(webcomic)));
                        //There is no page to update; back to the archive with you
                    }
                    return(View("Error", new ErrorViewModel {
                        RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                    }));
                }
            }
            return(await(new MainController()).Archive());
            //If the webcomic doesn't exist, you get kicked back to the main archive.
            //Should be impossible via in-app links.
        }
コード例 #3
0
        public async Task <IActionResult> GetNewPage(string WebcomicName)
        {
            _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            using (var _http = new HttpClient(_clientHandler))
            {
                var response = await _http.GetAsync(_webcomicsUri);

                if (response.IsSuccessStatusCode)
                {
                    var ComicBooks = JsonConvert.DeserializeObject <List <ComicBookModel> >(await response.Content.ReadAsStringAsync());

                    if (ComicBooks.FirstOrDefault(c => c.Title == WebcomicName) != null)
                    {
                        ComicBookModel webcomic = ComicBooks.FirstOrDefault(c => c.Title == WebcomicName);

                        if (User.Identity.Name != webcomic.Author)
                        {
                            //Impossible via in-application links; user is hacking. Back to main page,
                            //for lack of a more severe punishment.
                            return(View("MainArchiveView", new MainArchiveViewModel(ComicBooks)));
                        }

                        if (webcomic.ComicPages != null)
                        {
                            webcomic.ComicPages = webcomic.ComicPages.OrderBy(p => p.PageNumber).ToList();
                        }
                        ComicPageModel page = new ComicPageModel()
                        {
                            ComicBookId = webcomic.EntityId,
                            ComicBook   = webcomic
                        };
                        ComicPageViewModel pageview = new ComicPageViewModel(page);
                        return(View("NewPageView", pageview));
                    }
                    return(await(new MainController()).Archive());
                    //If the webcomic doesn't exist, kick them back to the archive of webcomics.
                    //Should be impossible via any in-application links.
                }
                return(View("Error", new ErrorViewModel {
                    RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                }));
            }
        }
コード例 #4
0
        public async Task <IActionResult> GetPage(string WebcomicName, int PageNumber)
        {
            _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

            using (var _http = new HttpClient(_clientHandler))
            {
                var response = await _http.GetAsync(_webcomicsUri);

                if (response.IsSuccessStatusCode)
                {
                    var ComicBooks = JsonConvert.DeserializeObject <List <ComicBookModel> >(await response.Content.ReadAsStringAsync());

                    if (ComicBooks.FirstOrDefault(c => c.Title == WebcomicName) != null)
                    {
                        ComicBookViewModel webcomic = new ComicBookViewModel(ComicBooks.FirstOrDefault(c => c.Title == WebcomicName));

                        webcomic.ComicPages.OrderBy(p => p.PageNumber);

                        //First, if there aren't any pages, you get sent to the About page instead of the
                        //latest page.
                        if (webcomic.NumberOfPages == 0)
                        {
                            return(await(new ComicsController()).GetAbout(WebcomicName));
                        }

                        if (webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber) != null)
                        {
                            ComicPageModel     page     = webcomic.ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber);
                            ComicPageViewModel pageview = new ComicPageViewModel(page);
                            if (PageNumber == pageview.FirstPageNumber)
                            {
                                return(View("FirstPageView", pageview));
                            }
                            if (PageNumber == 0 || PageNumber == webcomic.ComicPages[^ 1].PageNumber)
                            // PageNumber == 0 is the designation for default page (Latest)
                            {
                                return(View("LatestPageView", pageview));
                            }
                            return(View("MiddlePageView", pageview));
                        }
                        return(View("LatestPageView", new ComicPageViewModel(webcomic.ComicPages[^ 1])));