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
            }));
        }
        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
                }));
            }
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataBinding.CodeBinding"/> class.
        /// </summary>
        /// <param name="comicBook">Comic book.</param>
        public CodeBinding(ComicBookViewModel comicBook)
        {
            _comicBook = comicBook;
            InitPage();
            InitBindings();

            BackgroundColor = UIHelper.BackgroundColor;
            Title           = _comicBook.SeriesName;
        }
        public async Task <IActionResult> OnGet(int id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToPage("/Login"));
            }

            ComicBook = await _comicsController.GetByIdAsync(id);

            comicId = ComicBook.Id;
            return(Page());
        }
        public async Task AddToCollection(ComicBookViewModel cbvm, CollectionViewModel cvm)
        {
            if (cbvm == null)
            {
                return;
            }

            if (cvm == null)
            {
                return;
            }

            cbvm.CollectionId = cvm.Id;

            await _comicBookController.Edit(cbvm);
        }
Example #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])));
Example #7
0
        public async Task <IActionResult> PostWebcomic(ComicBookViewModel model)
        {
            if (ModelState.IsValid)
            {
                _clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); };

                using (var _http = new HttpClient(_clientHandler))
                {
                    var stringData    = JsonConvert.SerializeObject(new ComicBookModel(model));
                    var stringContent = new StringContent(stringData, UnicodeEncoding.UTF8, "application/json");
                    var response      = await _http.PostAsync(_webcomicsUri, stringContent);

                    if (response.IsSuccessStatusCode)
                    {
                        return(View("SuccessfulNewPageView"));
                    }
                    return(View("FailedNewPageView"));
                }
            }
            return(View("GetPostWebcomicView", model));
        }
        public async Task RemoveFromCollection(ComicBookViewModel cbvm, CollectionViewModel cvm)
        {
            if (cbvm == null)
            {
                return;
            }

            if (cvm == null)
            {
                return;
            }

            var comicBook = await _ctx.ComicBooks.FirstOrDefaultAsync(x => x.Id == cbvm.Id);

            if (comicBook == null)
            {
                return;
            }

            cbvm.CollectionId      = null;
            comicBook.CollectionId = null;

            await _ctx.SaveChangesAsync();
        }
        public XamlBinding(ComicBookViewModel comicBookVM)
        {
            BindingContext = comicBookVM;

            InitializeComponent();
        }