示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ApplicationUserId,ReadingListName")] ReadingList readingList)
        {
            if (id != readingList.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _context.ApplicationUsers.Where(u => u.Email == User.Identity.Name).FirstOrDefaultAsync();

                    readingList.ApplicationUserId = user.Id;
                    _context.Update(readingList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReadingListExists(readingList.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(readingList));
        }
        public void CreatesNewReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("returns_users_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                User user = new UserFixture().User();
                context.Users.Add(user);
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);

                ReadingList readingList = new ReadingList
                {
                    Title = "Existential Meltdown",
                    Books = new List <Book>()
                    {
                        new BookFixture().Book()
                    }
                };

                JsonResult result = controller.Post(readingList) as JsonResult;

                Assert.Equal(1, context.ReadingLists.Count());
                Assert.Equal(1, context.Books.Count());
                Assert.Equal(readingList, result.Value);
                Assert.Equal(1, readingList.Books[0].Ranking);
            }
        }
示例#3
0
        public ActionResult DeleteBook(int?id)
        {
            ReadingList xxx = _db.ReadingLists.Find(id);

            _db.ReadingLists.Remove(xxx);
            _db.SaveChanges();

            return(RedirectToAction("List"));
        }
        public JsonResult Post(ReadingList readingList)
        {
            User currentUser = _session.CurrentUser();

            readingList.Books[0].Ranking = 1;
            currentUser.ReadingLists.Add(readingList);
            _context.SaveChanges();

            return(Json(readingList));
        }
        public ActionResult Get(Guid readingListId)
        {
            ReadingList readingList = LoadReadingList(readingListId);

            if (readingList == null)
            {
                return(new NotFoundResult());
            }

            return(Json(readingList));
        }
        public ActionResult Delete(Guid readingListId, Guid bookId)
        {
            ReadingList readingList = LoadReadingList(readingListId);

            if (readingList == null)
            {
                return(new NotFoundResult());
            }

            readingList.RemoveBook(bookId);
            _context.SaveChanges();

            return(Json(readingList));
        }
        public ActionResult Patch(Guid readingListId, PatchData patchData)
        {
            ReadingList readingList = LoadReadingList(readingListId);

            if (readingList == null)
            {
                return(new NotFoundResult());
            }

            readingList.UpdateRankings(patchData.BookId, patchData.Ranking);
            _context.SaveChanges();

            return(Json(readingList));
        }
        public ActionResult Delete(Guid readingListId)
        {
            ReadingList readingList = LoadReadingList(readingListId);

            if (readingList == null)
            {
                return(new NotFoundResult());
            }

            _context.ReadingLists.Remove(readingList);
            _context.SaveChanges();

            return(Json(NoContent()));
        }
        public void HasManyBooks()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("has_many_books")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                context.ReadingLists.Add(new ReadingListFixture().ReadingList());
                context.SaveChanges();

                ReadingList readingList = context.ReadingLists.Last();
                Assert.Equal(3, readingList.Books.Count());
            }
        }
        public ActionResult Put(Guid readingListId, Book book)
        {
            ReadingList readingList = LoadReadingList(readingListId);

            if (readingList == null)
            {
                return(new NotFoundResult());
            }

            book.Ranking = readingList.Books.Count() + 1;
            readingList.Books.Add(book);
            _context.SaveChanges();

            return(Json(readingList));
        }
示例#11
0
        public void BelongsToReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("belongs_to_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                context.ReadingLists.Add(new ReadingListFixture().ReadingList());
                context.SaveChanges();

                Book        book        = context.Books.Last();
                ReadingList readingList = context.ReadingLists.Last();
                Assert.Equal(book.ReadingList.Title, readingList.Title);
            }
        }
        private async Task ReadItemsFromDiskWithRemoteFallback()
        {
            var readingListJson = await ReadItemFromFile(_applicationData.LocalFolder, "reading-list.json");

            ReadingList list;

            if (readingListJson == null)
            {
                if (App.HasConnectivity)
                {
                    // Get the reading list from Pocket
                    list = await ReadItLaterApi.GetReadingList();

                    // Save the reading list for future use
                    await WriteItemToFile(_applicationData.LocalFolder, "reading-list", list.Stringify());
                }
                else
                {
                    Debug.WriteLine("There was no cached list and we don't currently have Internet connectivity, aborting");

                    return;
                }
            }
            else
            {
                list = new ReadingList(readingListJson);
            }

            foreach (var item in list.List)
            {
                if (DEMO && Items.Count > 75)
                {
                    break;
                }

                Debug.WriteLine("Trying to read '{0}' from disk with remote fallback", item.Key);

                var diffbotArticle = await ReadItemFromDiskWithRemoteFallback(_applicationData.LocalFolder, item);

                if (diffbotArticle == null)
                {
                    continue;
                }

                AddItem(item.Value, diffbotArticle);
            }
        }
示例#13
0
        public BookRepositoryBase()
        {
            List <Book> arrayParaLer = new List <Book>();
            List <Book> arrayLendo   = new List <Book>();
            List <Book> arrayLidos   = new List <Book>();

            using (var file = File.OpenText(nomeArquivoCSV))
            {
                while (!file.EndOfStream)
                {
                    var textoLivro = file.ReadLine();
                    if (string.IsNullOrEmpty(textoLivro))
                    {
                        continue;
                    }
                    var infoLivro = textoLivro.Split(';');
                    var livro     = new Book
                    {
                        Id     = Convert.ToInt32(infoLivro[1]),
                        Titulo = infoLivro[2],
                        Autor  = infoLivro[3]
                    };
                    switch (infoLivro[0])
                    {
                    case "para-ler":
                        arrayParaLer.Add(livro);
                        break;

                    case "lendo":
                        arrayLendo.Add(livro);
                        break;

                    case "lidos":
                        arrayLidos.Add(livro);
                        break;

                    default:
                        break;
                    }
                }
            }

            ParaLer = new ReadingList("Para Ler", arrayParaLer.ToArray());
            Lendo   = new ReadingList("Lendo", arrayLendo.ToArray());
            Lidos   = new ReadingList("Lidos", arrayLidos.ToArray());
        }
示例#14
0
        public ActionResult ReadingList(ReadingList model)
        {
            var list = new ReadingList();


            list.KitapId      = model.KitapId;
            list.UserName     = model.UserName;
            list.AdditionTime = DateTime.Now;
            _db.ReadingLists.Add(model);
            _db.SaveChanges();

            return(RedirectToAction("List", "Home"));



            //list.KitapId=model.KitapId;
            //list.UserName = model.UserName;
            //list.AdditionTime = DateTime.Now;

            //_db.ReadingLists.Add(model);
            //_db.SaveChanges();
        }
示例#15
0
        public ReadingList GetReadingItemList()
        {
            ReadingList readingList = new ReadingList();

            readingList.ReadingItems = new List <ReadingListItem>
            {
                new ReadingListItem
                {
                    Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vulputate, ante vel commodo hendrerit, justo ante sagittis metus, eu fringilla.",
                    LogoUrl     = "https://bulma.io/images/placeholders/96x96.png",
                    ReadingId   = Guid.NewGuid(),
                    Title       = "Lorem ipsum dolor sit amet"
                },
                new ReadingListItem()
                {
                    Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vulputate, ante vel commodo hendrerit, justo ante sagittis metus, eu fringilla.",
                    LogoUrl     = "https://bulma.io/images/placeholders/96x96.png",
                    ReadingId   = Guid.NewGuid(),
                    Title       = "Lorem ipsum dolor sit amet"
                },
                new ReadingListItem()
                {
                    Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vulputate, ante vel commodo hendrerit, justo ante sagittis metus, eu fringilla.",
                    LogoUrl     = "https://bulma.io/images/placeholders/96x96.png",
                    ReadingId   = Guid.NewGuid(),
                    Title       = "Lorem ipsum dolor sit amet"
                },
                new ReadingListItem()
                {
                    Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vulputate, ante vel commodo hendrerit, justo ante sagittis metus, eu fringilla.",
                    LogoUrl     = "https://bulma.io/images/placeholders/96x96.png",
                    ReadingId   = Guid.NewGuid(),
                    Title       = "Lorem ipsum dolor sit amet"
                }
            };

            return(readingList);
        }
示例#16
0
        private async Task WriteViewModelToDbAsync(Ao3PageViewModel viewmodel, ReadingList dbentry)
        {
            bool changed = false;

            if (dbentry.Unread != viewmodel.Unread)
            {
                changed        = true;
                dbentry.Unread = viewmodel.Unread;
            }

            string model = Ao3PageModel.Serialize(viewmodel.BaseData);

            if (!(model is null) && dbentry.Model != model)
            {
                changed       = true;
                dbentry.Model = model;
            }

            if (changed)
            {
                await App.Database.ReadingListCached.InsertOrUpdateAsync(dbentry);
            }
        }
示例#17
0
        public ReadingList ReadingList()
        {
            Book book1 = new Book
            {
                Title   = "On The Plurality Of Worlds",
                Authors = new string[] { "David Lewis" },
                Image   = "test image url",
                Ranking = 1
            };

            Book book2 = new Book
            {
                Title   = "An Inquiry Concerning The Principles Of Morals",
                Authors = new string[] { "David Hume" },
                Image   = "test image url",
                Ranking = 2
            };

            Book book3 = new Book
            {
                Title   = "Critique Of Pure Reason",
                Authors = new string[] { "Immanuel Kant" },
                Image   = "test image url",
                Ranking = 3
            };

            ReadingList readingList = new ReadingList
            {
                Title = "Existential Meltdown",
                Books = new List <Book>()
                {
                    book1, book2, book3
                }
            };

            return(readingList);
        }
示例#18
0
        public MainViewModel()
        {
            ApiBaseUrl     = "";
            ConsumerKey    = "";
            ConsumerSecret = "";

            ProgressVisible = false;
            DataStorage     = new DataStorage();
            BookmarkList    = new BookmarkList();

            ReadabilityClient = new ReadabilityApi.ReadabilityClient(ApiBaseUrl, ConsumerKey, ConsumerSecret);

            Observable.Buffer(Observable.FromEventPattern(this, "ReadingListUpdated").Throttle(TimeSpan.FromSeconds(1)), 1)
            .Subscribe(e =>
            {
                ShellTile tile = ShellTile.ActiveTiles.First();
                if (tile != null && ReadingList.Count > 0)     //Do nothing if there's no tile pinned or there are no items in the list.
                {
                    var firstArticleInReadingList = ReadingList.First().Article;

                    IconicTileData TileData = new IconicTileData()
                    {
                        Title           = "Now Readable",
                        Count           = ReadingListCount,
                        WideContent1    = firstArticleInReadingList.Title,
                        WideContent2    = firstArticleInReadingList.Excerpt.Substring(0, 100),
                        WideContent3    = firstArticleInReadingList.Author,
                        SmallIconImage  = new Uri("Assets/Tiles/SmallIconImage.png", UriKind.Relative),
                        IconImage       = new Uri("Assets/Tiles/IconImage.png", UriKind.Relative),
                        BackgroundColor = System.Windows.Media.Colors.Red
                    };

                    tile.Update(TileData);
                }
            });
        }
示例#19
0
        private void GoToReadingList()
        {
            ReadingList f2 = new ReadingList();

            f2.Show();
        }
        protected override void Execute()
        {
            Ao3PageViewModel item = Target as Ao3PageViewModel;

            ReadingList?.Goto(item, true, false);
        }
 protected override void Execute()
 {
     ReadingList?.Goto(Target, true, true);
 }
示例#22
0
        // POST: api/ReadingList
        public ReadingList Post([FromBody] ReadingList incoming)
        {
            using (var ctx = new Models.Ao3TrackEntities())
            {
                var changes = new Dictionary <string, long>();

                var existing = (from i in ctx.ReadingLists where i.userid == User.id select i).ToDictionary(i => i.path);
                Models.ReadingList ls;
                if (existing.TryGetValue("", out ls))
                {
                    existing.Remove("");
                }
                else
                {
                    ls = ctx.ReadingLists.Add(new Models.ReadingList {
                        userid = User.id, path = "", timestamp = 0
                    });
                }
                var latest = ls.timestamp;

                foreach (var item in existing)
                {
                    if (item.Value.timestamp > latest)
                    {
                        latest = item.Value.timestamp;
                    }

                    if (!incoming.paths.ContainsKey(item.Key))
                    {
                        if (item.Value.timestamp >= incoming.last_sync)
                        {
                            // Item was added and needs to be sent to client
                            changes.Add(item.Key, item.Value.timestamp);
                        }
                        else
                        {
                            // Client deleted item since we last sent it
                            ctx.ReadingLists.Remove(item.Value);
                        }
                    }
                    else
                    {
                        incoming.paths.Remove(item.Key);
                    }
                }

                foreach (var item in incoming.paths)
                {
                    if (item.Value > latest)
                    {
                        latest = item.Value;
                    }

                    if (!existing.ContainsKey(item.Key))
                    {
                        if (item.Value >= ls.timestamp)
                        {
                            // Item is NEW!
                            ctx.ReadingLists.Add(new Models.ReadingList
                            {
                                userid = User.id, path = item.Key, timestamp = item.Value
                            });
                        }
                        else
                        {
                            // Item was previously deleted and client needs to be notified
                            changes.Add(item.Key, -1);
                        }
                    }
                }

                ls.timestamp = latest + 1;

                ctx.SaveChanges();

                return(new ReadingList {
                    last_sync = ls.timestamp, paths = changes
                });
            }
        }
示例#23
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ReadingList f2 = new ReadingList();
     f2.Show();
 }