Ejemplo n.º 1
0
        protected override void Seed(BookDBContext context)
        {
            localhost.DataStorage storage = new localhost.DataStorage();
            IList <S4452232>      books   = new List <S4452232>();

            string[] bookList = storage.Read();

            for (int i = 0; i < bookList.Length; i++)
            {
                string[] elements = bookList[i].Split(',');
                S4452232 book     = new S4452232 {
                    Index  = i + 1,
                    ID     = elements[0],
                    Name   = elements[1],
                    Author = elements[2],
                    Year   = int.Parse(elements[3]),
                    Price  = decimal.Parse(elements[4].Substring(1)),
                    Stock  = int.Parse(elements[5])
                };
                books.Add(book);
            }

            foreach (S4452232 book in books)
            {
                context.S4452232.Add(book);
            }

            base.Seed(context);
        }
Ejemplo n.º 2
0
        protected virtual void SaveBooks(List <S4452232> books)
        {
            localhost.DataStorage storage = new localhost.DataStorage();
            string bookList = string.Empty;

            foreach (S4452232 book in books)
            {
                bookList += BookToString(book) + '\n';
            }
            storage.Write(bookList.Substring(0, bookList.Length - 1));
        }