ViewModel.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WpfApp1
  7. {
  8. class ViewModel
  9. {
  10. public List<Books> books;
  11. public ViewModel()
  12. {
  13. books = newbook();
  14. }
  15. public List<Books> newbook()
  16. {
  17. List<Books> allBook = new List<Books>();
  18. Books buff;
  19. List<Books> BDBooks = DataBAse.BaseModel.Books.ToList();
  20. foreach(Books book in BDBooks)
  21. {
  22. buff = new Books();
  23. buff.IdBook = book.IdBook;
  24. buff.Title = book.Title;
  25. buff.IdGenre = book.IdGenre;
  26. buff.IdAuthor = book.IdAuthor;
  27. buff.allDescription = "Описание: " + book.Description;
  28. buff.Image = book.Image;
  29. buff.CountInStock = book.CountInStock;
  30. buff.CountInStore = book.CountInStore;
  31. buff.Cost = book.Cost;
  32. Authors authors = DataBAse.BaseModel.Authors.FirstOrDefault(x => x.IdAuthor == book.IdAuthor);
  33. buff.nameAuthor = authors.Name;
  34. Genres genre = DataBAse.BaseModel.Genres.FirstOrDefault(x => x.IdGenre == book.IdGenre);
  35. buff.tittleGenre = genre.GenreName;
  36. if(book.CountInStock > 5)
  37. {
  38. buff.Stock = "много";
  39. }
  40. else if(book.CountInStock == 0)
  41. {
  42. buff.Stock = "нет";
  43. }
  44. else
  45. {
  46. buff.Stock = book.CountInStock;
  47. }
  48. if (book.CountInStore > 5)
  49. {
  50. buff.Store = "много";
  51. }
  52. else if (book.CountInStore == 0)
  53. {
  54. buff.Store = "нет";
  55. }
  56. else
  57. {
  58. buff.Store = book.CountInStore;
  59. }
  60. allBook.Add(buff);
  61. }
  62. return allBook;
  63. }
  64. }
  65. }