public static void Main(string[] args) { Console.WriteLine("Hello World!"); // TODO: Implement Functionality Here IBookManager bm = BookManagerFactory.GetBookManager(); User moi = bm.GetAllUsers().SingleOrDefault(x => x.Identifier == 1); List <Book> allBooks = bm.GetAllBooks(); //var allUserBooks = bm.GetAllUserBooks(); IBookSelecter selecter = new ContinueSerie(); IBookSelecter selecter2 = new NewAuthor(); IBookSelecter selecter3 = new TerminerSerie(); IBookSelecter selecter4 = new VieuxTruc(); IBookSelecter selecter5 = new ViteLu(); IBookSelecter selecter6 = new RecentlyAdded(); IBookSelecter selecter7 = new OneShot(); IBookSelecter selecter8 = new StartNewSerie(); BookSelecterCriteria criteria = new BookSelecterCriteria() { AuthorLike = "nath" }; TrySelecter(selecter7, allBooks, criteria, moi); // TrySelecter(selecter2, allBooks, criteria, moi); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { var alreadyRead = allBooks.Where(x => x.HasBeenReadBy(user)); var selection = Helper.ApplySearchCriteria(alreadyRead, criteria, user); return(selection.OrderByDescending(x => x.Experiences.Single(y => y.UserId == user.Identifier).DateRead).ToList()); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { List <Book> booksToRead = Helper.GetBooksToRead(allBooks, user); booksToRead = Helper.ApplySearchCriteria(booksToRead, criteria, user).ToList(); booksToRead = booksToRead.OrderBy(emp => Guid.NewGuid()).ToList(); return(booksToRead); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { List <Book> result = Helper.GetBooksToRead(allBooks, user); result = Helper.ApplySearchCriteria(result, criteria, user); result.RemoveAll(x => x.DateAdded < DateTime.Now.AddMonths(-1)); result = result.OrderBy(emp => Guid.NewGuid()).ToList(); return(result); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { Random rand = new Random(); var selection = Helper.GetBooksToRead(allBooks, user).Where(x => string.IsNullOrEmpty(x.Serie)); //Filters selection = Helper.ApplySearchCriteria(selection, criteria, user); selection = selection.OrderBy(emp => Guid.NewGuid()).ToList(); return(selection.ToList()); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { List <Book> booksToRead = Helper.GetBooksToRead(allBooks, user); var ordered = booksToRead.OrderBy(x => x.DateAdded); DateTime limit = ordered.ElementAt(ordered.Count() / 10).DateAdded; //keep only the 10% oldest books var selection = booksToRead.Where(x => x.DateAdded < limit).ToList(); selection = Helper.ApplySearchCriteria(selection, criteria, user); selection = selection.OrderBy(emp => Guid.NewGuid()).ToList(); return(selection); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { var toRead = Helper.GetBooksToRead(allBooks, user); //Removed one-shots and prequels toRead.RemoveAll(x => x.SerieIndex == 0 || string.IsNullOrEmpty(x.Serie)); toRead = Helper.ApplySearchCriteria(toRead, criteria, user); toRead.RemoveAll(x => x.SerieIndex == 1 || x.SerieIndex != allBooks.Where(y => y.Serie == x.Serie).Max(y => y.SerieIndex)); toRead.RemoveAll(x => x.SerieIndex == allBooks.Where(y => x.Serie == y.Serie).Min(y => y.SerieIndex)); toRead = toRead.OrderBy(emp => Guid.NewGuid()).ToList(); return(toRead); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { Random rand = new Random(); IEnumerable <Book> selection = Helper.GetBooksToRead(allBooks, user); //Filters selection = Helper.ApplySearchCriteria(selection, criteria, user); //Keep only series and first volume selection = selection.Where(x => x.Serie != string.Empty && x.SerieIndex == 1); selection = selection.OrderBy(emp => Guid.NewGuid()).ToList(); return(selection.ToList()); }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { Random rand = new Random(); var knownAuthors = allBooks.Where(x => x.Experiences.Any(y => y.Read)).SelectMany(x => x.Authors).Distinct(); //var knownAuthors = allBooks.Where(x => x.GetUserBook(user).Read).SelectMany(x => x.Authors).Distinct(); IEnumerable <Book> selection = Helper.GetBooksToRead(allBooks, user); selection = Helper.ApplySearchCriteria(selection, criteria, user); selection = selection.Where(x => !(x.Authors.Intersect(knownAuthors).Any())); selection = selection.OrderBy(emp => Guid.NewGuid()).ToList(); return(selection.ToList()); }
public static List <Book> ApplySearchCriteria(IEnumerable <Book> selection, BookSelecterCriteria criteria, User user) { if (!string.IsNullOrEmpty(criteria.AuthorLike)) { selection = selection.Where(x => x.Authors.Any(y => y.CaseContains(criteria.AuthorLike))); } if (!string.IsNullOrEmpty(criteria.Tag)) { selection = selection.Where(x => x.Tags.Contains(criteria.Tag)); } if (!string.IsNullOrEmpty(criteria.Language)) { selection = selection.Where(x => x.Language.Equals(criteria.Language)); } if (!string.IsNullOrEmpty(criteria.TitleLike)) { selection = selection.Where(x => x.Title.CaseContains(criteria.TitleLike)); } if (!string.IsNullOrEmpty(criteria.SerieLike)) { selection = selection.Where(x => x.Serie.CaseContains(criteria.SerieLike)); } if (criteria.EnvieMin > 0) { selection = selection.Where(x => x.GetRating(user) >= criteria.EnvieMin); } if (criteria.MinPages > 0) { selection = selection.Where(x => x.Pages >= criteria.MinPages); } if (criteria.MaxPages > 0) { selection = selection.Where(x => x.Pages <= criteria.MaxPages); } return(selection.ToList()); }
protected void mButton_Click(object sender, EventArgs e) { IBookSelecter selecter = mSelectersDropDownList.SelectedSelecter; Session["Selecter"] = selecter; List <Book> allBooks = (List <Book>)Session["Books"]; User user = (User)Session["User"]; int rating = 0; int.TryParse(mtxtRating.Text, out rating); int minPages = 0; int.TryParse(mtxtMinPages.Text, out minPages); int maxPages = 0; int.TryParse(mtxtMaxPages.Text, out maxPages); var criteria = new BookSelecterCriteria() { Tag = mTagsDropDownList.SelectedValue, Language = mLanguagesDropDownList.SelectedValue, AuthorLike = mtxtAuthor.Text, SerieLike = mtxtSerie.Text, TitleLike = mtxtTitle.Text, EnvieMin = rating, MinPages = minPages, MaxPages = maxPages }; List <Book> myBooks = selecter.SelectBooks(allBooks, criteria, user); Session["SelectedBooks"] = myBooks; if (myBooks.Any()) { Response.Redirect("~/"); } else { mlblMessage.Text = "Aucun résultat"; } }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { Random rand = new Random(); List <Book> result = new List <Book>(); //remove already read books var selection = allBooks.Where(x => !string.IsNullOrEmpty(x.Serie) && x.SerieIndex > 0); //Filters selection = Helper.ApplySearchCriteria(selection, criteria, user); //selection = selection.Where(x => x.SerieIndex != 1 && x.SerieIndex == selection.Where(y => y.Serie.Equals(x.Serie) && y.Read == false).Select(z => z.SerieIndex).Min()); var seriesNames = selection.Select(x => x.Serie).Distinct(); foreach (string serie in seriesNames) { var booksOfTheSerie = selection.Where(x => x.Serie.Equals(serie)); if (booksOfTheSerie.Any(x => !x.HasBeenReadBy(user)) && booksOfTheSerie.Any(x => x.HasBeenReadBy(user))) { //La série contient des non lus booksOfTheSerie = booksOfTheSerie.OrderBy(x => x.SerieIndex); Book nextBookForThisSerie = booksOfTheSerie.First(x => !x.HasBeenReadBy(user)); if (booksOfTheSerie.Where(x => x.SerieIndex < nextBookForThisSerie.SerieIndex).All(x => x.HasBeenReadBy(user)) && nextBookForThisSerie.SerieIndex > 1) { //Les livres précédents ont été lus result.Add(nextBookForThisSerie); } } } result = result.OrderBy(emp => Guid.NewGuid()).ToList(); return(result); }
private static void TrySelecter(IBookSelecter selecter, List <Book> allBooks, BookSelecterCriteria criteria, User user) { Console.WriteLine("========================================================="); Console.WriteLine("Testing Selecter " + selecter.GetDescription()); Console.WriteLine(); List <Book> theBooks = selecter.SelectBooks(allBooks, criteria, user); Console.WriteLine("Books count : " + theBooks.Count); for (int i = 1; i <= theBooks.Count; i++) { Console.WriteLine(string.Format("{0}/{1} : {2}", i, theBooks.Count, theBooks[i - 1])); } }
public List <Book> SelectBooks(List <Book> allBooks, BookSelecterCriteria criteria, User user) { var selection = Helper.ApplySearchCriteria(allBooks, criteria, user); return(selection.OrderBy(emp => Guid.NewGuid()).ToList()); }