123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace test
- {
- class ViewModel
- {
- public List<Books> books;
- public ViewModel()
- {
- books = newbooks();
- }
- public List<Books> newbooks()
- {
- List<Books> allbooks = new List<Books>();
- List<Books> bdbooks = Base.Entities.Books.ToList();
- Books buff;
- foreach(Books books in bdbooks)
- {
- buff = new Books();
- buff.IdBook = books.IdBook;
- buff.Title = books.Title;
- buff.Genre = books.Genre;
- buff.Author = books.Author;
- buff.des = "Описание: " + books.Description;
- buff.Image = books.Image;
- buff.CountInStock = books.CountInStock;
- buff.CountInStore = books.CountInStore;
- buff.Cost = books.Cost;
- Authors authors = Base.Entities.Authors.FirstOrDefault(x => x.IdAuthor == books.Author);
- buff.nameAuttor = authors.Name;
- Genre genre = Base.Entities.Genre.FirstOrDefault(x => x.IdGenre == books.Genre);
- buff.titleGenre = genre.Genre1;
- if(books.CountInStock > 5)
- {
- buff.Stock = "many";
- }
- else if(books.CountInStock == 0)
- {
- buff.Stock = "no";
- }
- else
- {
- buff.Stock = books.CountInStock;
- }
- allbooks.Add(buff);
- }
- return allbooks;
- }
- }
- }
|