예제 #1
0
 public ComicPage()
 {
     InitializeComponent();
     _viewModel            = new ComicPageViewModel();
     _viewModel.Navigation = Navigation;
     BindingContext        = _viewModel;
 }
예제 #2
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));

                        //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));
                        }

                        List <ComicPageModel> ComicPages = webcomic.ComicPages.OrderBy(p => p.PageNumber).ToList();
                        ComicPageModel        page;
                        ComicPageViewModel    pageview;
                        if (ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber) != null)
                        {
                            page           = ComicPages.FirstOrDefault(p => p.PageNumber == PageNumber);
                            page.ComicBook = new ComicBookModel(webcomic);
                            pageview       = new ComicPageViewModel(page);
                            if (PageNumber == pageview.FirstPageNumber)
                            {
                                return(View("FirstPageView", pageview));
                            }
                            if (PageNumber == 0 || PageNumber == ComicPages[^ 1].PageNumber)
                            // PageNumber == 0 is the designation for default page (Latest)
                            {
                                return(View("LatestPageView", pageview));
                            }
                            return(View("MiddlePageView", pageview));
                        }
                        page           = ComicPages.Last();
                        page.ComicBook = new ComicBookModel(webcomic);
                        pageview       = new ComicPageViewModel(page);
                        return(View("LatestPageView", pageview));
                        //If the page number is invalid, send to the default page (Latest).
                        //Should be impossible via any in-application links.
                    }
                    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
                }));
            }
        }
예제 #3
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.
        }
예제 #4
0
        public IActionResult Index(Guid?pageId)
        {
            ComicPage comicPage = pageId is null
                ? _defaultComicPageRetriever.RetrieveDefaultComicPage()
                : _comicPageFromIdRetriever.RetrieveComicPageFromId(pageId.Value);

            ComicIssue comicIssue = _comicIssueResolver.ResolveComicIssue(comicPage.IssueId);

            ComicPageViewModel comicPageViewModel = new ComicPageViewModel()
            {
                ComicPage  = comicPage,
                ComicIssue = comicIssue
            };

            return(View(comicPageViewModel));
        }
예제 #5
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
                }));
            }
        }
예제 #6
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])));
예제 #7
0
        public async Task <IActionResult> UpdatePage(ComicPageViewModel page)
        {
            if (ModelState.IsValid)
            {
                _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

                using (var _http = new HttpClient(_clientHandler))
                {
                    var stringData    = JsonConvert.SerializeObject(new ComicPageModel(page));
                    var stringContent = new StringContent(stringData, UnicodeEncoding.UTF8, "application/json");
                    var response      = await _http.PutAsync(_pagesUri, stringContent);

                    if (response.IsSuccessStatusCode)
                    {
                        return(View("SuccessfulNewPageView", page));
                    }
                    return(View("Error", new ErrorViewModel {
                        RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                    }));
                }
            }
            return(View("FailedNewPageView", page));
        }
예제 #8
0
        // GET: Comic/Page
        public ActionResult Page(int id)
        {
            ComicPageViewModel model = new ComicPageViewModel();

            return(View(model));
        }
 public ComicPage()
 {
     InitializeComponent();
     BindingContext = new ComicPageViewModel();
 }