ViewModel.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace test
  8. {
  9. class ViewModel
  10. {
  11. public List<Books> books;
  12. public ViewModel()
  13. {
  14. books = newbooks();
  15. }
  16. public List<Books> newbooks()
  17. {
  18. List<Books> allbooks = new List<Books>();
  19. List<Books> bdbooks = Base.Entities.Books.ToList();
  20. Books buff;
  21. foreach(Books books in bdbooks)
  22. {
  23. buff = new Books();
  24. buff.IdBook = books.IdBook;
  25. buff.Title = books.Title;
  26. buff.Genre = books.Genre;
  27. buff.Author = books.Author;
  28. buff.des = "Описание: " + books.Description;
  29. buff.Image = books.Image;
  30. buff.CountInStock = books.CountInStock;
  31. buff.CountInStore = books.CountInStore;
  32. buff.Cost = books.Cost;
  33. Authors authors = Base.Entities.Authors.FirstOrDefault(x => x.IdAuthor == books.Author);
  34. buff.nameAuttor = authors.Name;
  35. Genre genre = Base.Entities.Genre.FirstOrDefault(x => x.IdGenre == books.Genre);
  36. buff.titleGenre = genre.Genre1;
  37. if(books.CountInStock > 5)
  38. {
  39. buff.Stock = "many";
  40. }
  41. else if(books.CountInStock == 0)
  42. {
  43. buff.Stock = "no";
  44. }
  45. else
  46. {
  47. buff.Stock = books.CountInStock;
  48. }
  49. allbooks.Add(buff);
  50. }
  51. return allbooks;
  52. }
  53. }
  54. }