using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp1
{
    class ViewModel
    {
        public List<Books> books;

        public ViewModel()
        {
            books = newbook();
        }

        public List<Books> newbook()
        {
            List<Books> allBook = new List<Books>();
            Books buff;
            List<Books> BDBooks = DataBAse.BaseModel.Books.ToList();

            foreach(Books book in BDBooks)
            {
                buff = new Books();
                buff.IdBook = book.IdBook;
                buff.Title = book.Title;
                buff.IdGenre = book.IdGenre;
                buff.IdAuthor = book.IdAuthor;
                buff.allDescription = "Описание: " + book.Description;
                buff.Image = book.Image;
                buff.CountInStock = book.CountInStock;
                buff.CountInStore = book.CountInStore;
                buff.Cost = book.Cost;

                Authors authors = DataBAse.BaseModel.Authors.FirstOrDefault(x => x.IdAuthor == book.IdAuthor);
                buff.nameAuthor = authors.Name;

                Genres genre = DataBAse.BaseModel.Genres.FirstOrDefault(x => x.IdGenre == book.IdGenre);
                buff.tittleGenre = genre.GenreName;

                if(book.CountInStock > 5)
                {
                    buff.Stock = "много";
                }
                else if(book.CountInStock == 0)
                {
                    buff.Stock = "нет";
                }
                else
                {
                    buff.Stock = book.CountInStock;
                }

                if (book.CountInStore > 5)
                {
                    buff.Store = "много";
                }
                else if (book.CountInStore == 0)
                {
                    buff.Store = "нет";
                }
                else
                {
                    buff.Store = book.CountInStore;
                }
                allBook.Add(buff);
            }
            return allBook;
        }
    }
}
