コード例 #1
0
        public async Task <string> StartUp()
        {
            ReadingListRepository <Recommendation> .Initialize();

            await ReadingListRepository <Recommendation> .StartUpMode();

            return("success");
        }
コード例 #2
0
        public async Task <IEnumerable <Recommendation> > GetRecommendations()
        {
            ReadingListRepository <Recommendation> .Initialize();

            IEnumerable <Recommendation> recomms = (IEnumerable <Recommendation>) await ReadingListRepository <Recommendation> .GetBooks(d => d.type == "recommendation");

            return(recomms);
        }
コード例 #3
0
        public async Task <string> DeleteBook(string id)
        {
            ReadingListRepository <Book> .Initialize();

            await ReadingListRepository <Book> .RemoveBookForUser(id);

            return("success");
        }
コード例 #4
0
        public async Task <IActionResult> Deploy()
        {
            ReadingListRepository <Recommendation> .Initialize();

            await ReadingListRepository <Recommendation> .StartUpMode();

            return(RedirectToAction("Index", "ReadingList"));
        }
コード例 #5
0
        public async Task <IEnumerable <Book> > GetUsersBooks()
        {
            ReadingListRepository <Book> .Initialize();

            IEnumerable <Book> myBooks = (IEnumerable <Book>) await ReadingListRepository <Book> .GetBooksForUser(b => b.reader == Settings.readerName);

            return(myBooks);
        }
コード例 #6
0
        public async Task <Book> GetBook(string id)
        {
            //get the requested record.
            ReadingListRepository <Book> .Initialize();

            IEnumerable <Book> myBooks = (IEnumerable <Book>) await ReadingListRepository <Book> .GetBooksForUser(b => b.id == id.ToString());

            return(myBooks.First());
        }
コード例 #7
0
        public async Task <string> SaveBook([FromBody] string content)
        {
            ReadingListRepository <Book> .Initialize();

            Book myBookToSave = JsonConvert.DeserializeObject <Book>(content);

            await ReadingListRepository <Book> .UpsertBookForUser(myBookToSave);

            return("Success");
        }
コード例 #8
0
        // GET: ReadingList
        public async Task <ActionResult> Index()
        {
            ReadingListViewModel readingListContent = new ReadingListViewModel();

            readingListContent.LibraryBooks = await ReadingListRepository <Recommendation> .GetBooks(d => d.type == "recommendation");

            ReadingListRepository <Book> .Initialize();

            readingListContent.MyBooks = (IEnumerable <Book>) await ReadingListRepository <Book> .GetBooksForUser(b => b.reader == Settings.readerName);

            return(View(readingListContent));
        }
コード例 #9
0
        // GET: ReadingList/Delete/5
        public async Task <ActionResult> Delete(string id)
        {
            try
            {
                ReadingListRepository <Book> .Initialize();

                await ReadingListRepository <Book> .RemoveBookForUser(id);
            }
            catch (Exception ex)
            {
            }
            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public async Task <ActionResult> Edit(string id, IFormCollection collection)
        {
            try
            {
                Book updatedBook = SaveCollectionAsBook(collection);

                ReadingListRepository <Book> .Initialize();

                await ReadingListRepository <Book> .UpsertBookForUser(updatedBook);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #11
0
        public async Task <ActionResult> Create(IFormCollection collection)
        {
            try
            {
                Book myNewBookToSave = SaveCollectionAsBook(collection);

                ReadingListRepository <Book> .Initialize();

                await ReadingListRepository <Book> .UpsertBookForUser(myNewBookToSave);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
コード例 #12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=ReadingList}/{action=Index}/{id?}");
            });

            ReadingListRepository <Recommendation> .Initialize();
        }