public Book(Bestseller book) { this.Title = book.Title; this.Author = book.Author; this.ImageSrc = book.ImageSrc; this.Store = book.Store; }
public IconDto(Bestseller agent, int count) { this.id = agent.ImageSrc; this.type = "BOOK"; this.title = agent.Title + "||" + agent.Author; this.setLocation(false); this.count = count.ToString(); this.countValue = count; this.source = agent.Store; this.tags = agent.getTags(); this.playAt = agent.Added.HasValue? agent.Added.Value : DateTime.Now; this.guidId = agent.ID.ToString(); }
public IActionResult GetBestsellerList() { var orders = _db.Orders.ToList(); var booksDictionary = new Dictionary <int, int>(); foreach (var order in orders) { var books = _db.Items.Where(i => i.OrderId == order.Id).ToList(); foreach (var book in books) { if (booksDictionary.ContainsKey(book.BookId)) { booksDictionary[book.BookId] += book.Quantity; } else { booksDictionary.Add(book.BookId, book.Quantity); } } } var result = (from t in booksDictionary orderby t.Value descending select t).Take(5); List <Bestseller> list = new List <Bestseller>(); foreach (var item in result) { var book = _db.Books.Find(item.Key); if (book == null) { continue; } var zanr = _db.Categories.Find(book.CategoryId); book.Category = zanr; var bestseller = new Bestseller() { TheBook = book, Quantity = item.Value }; list.Add(bestseller); } return(View(list)); }
public DtoBestseller(Bestseller best) { Count = best.Count; Price = best.Price; Date = best.Date.Day.ToString() + "." + best.Date.Month.ToString() + "." + best.Date.Year.ToString(); }
public async Task BooksUpdateAsync() { Console.WriteLine("Start updatign books"); var bestList = new List <Book>(); await _context.SaveChangesAsync(); var bonitos = await new Bonito().GetBestsellersAsync(); bestList.AddRange(bonitos); var aros = await new Aros().GetBestsellersAsync(); bestList.AddRange(aros); var czytams = await new Czytam().GetBestsellersAsync(); bestList.AddRange(czytams); var empiks = await new Empik().GetBestsellersAsync(); bestList.AddRange(empiks); var gandalfs = await new Gandalf().GetBestsellersAsync(); bestList.AddRange(gandalfs); var livros = await new Livro().GetBestsellersAsync(); bestList.AddRange(livros); var profit24s = await new Profit24().GetBestsellersAsync(); bestList.AddRange(profit24s); Log.Information($"Finish bestsellers update with {bestList.Count} books"); Log.Information($"{bonitos.Count} from Bonito"); Log.Information($"{aros.Count} from Aros"); Log.Information($"{czytams.Count} from Czytam"); Log.Information($"{empiks.Count} from Empik"); Log.Information($"{gandalfs.Count} from Gandalf"); Log.Information($"{livros.Count} from Livro"); Log.Information($"{profit24s.Count} from Profit24"); var actualBestsellers = _context.Bestsellers.ToList(); _context.Bestsellers.RemoveRange(_context.Bestsellers.Where(x => x.Store != "")); _context.SaveChanges(); int group = 1; foreach (var book in bestList) { var theSameList = bestList.Where(x => x.GroupNo == -1) .Where(x => x.TheSame(book.Title, book.Author)).ToList(); if (theSameList.Count > 0) { foreach (var theSameBook in theSameList) { theSameBook.GroupNo = group; } group++; } } int no = 1; foreach (var book in bestList) { var exists = actualBestsellers.FirstOrDefault(x => x.ImageSrc == book.ImageSrc); if (exists != null) { Console.WriteLine("Added exists"); exists.Added = DateTime.Now; var theSame = bestList .FirstOrDefault(x => x.TheSame(exists.Title, exists.Author)); if (theSame != null) { exists.SetGroupNo(theSame.GroupNo); } else { int max = bestList.Select(x => x.GroupNo).Max() + no; no++; exists.SetGroupNo(max); } await _context.Bestsellers.AddAsync(exists); } else { var bestseller = new Bestseller(book); bestseller.Added = DateTime.Now; Console.WriteLine("Added new"); await _context.Bestsellers.AddAsync(bestseller); } } await _context.SaveChangesAsync(); InfoCaches._booksUpdatingRunning = true; // Console.WriteLine("========Finish book update=========="); }
public void AddBestsellers(Bestseller bestseller) { bestseller.UserId = GetUserId(); _service.AddBest(bestseller); }
public void AddBest(Bestseller best) { _repository.Add(best); }