public BookRepository()
        {
            jw = new JsonWorker();
            var fileinfo = new FileInfo(path);

            if (fileinfo.Exists)
            {
                data = jw.Load(path).ToList();
            }
            else
            {
                data = new List <Book>
                {
                    new Book {
                        Id          = 1, Title = "How to Win Friends and Influence People",
                        Description = "Книга представляет собой собрание практических советов и жизненных историй.",
                        Author      = "Dale Harbison Carnegie", Created = new DateTime(1936, 1, 1),
                        Genre       = Genre.Essay, IsPaper = true, Languages = new[] { 3 }, DeliveryRequired = true
                    },
                    new Book {
                        Id    = 2, Title = "CLR VIA C#", Description = "Book for C# programmers", Author = "Jeffrey Richter", Created = new DateTime(2006, 1, 1),
                        Genre = Genre.ReferenceBooks, IsPaper = true, Languages = new[] { 1, 3 }, DeliveryRequired = true
                    },
                    new Book {
                        Id    = 3, Title = "Cashflow Quadrant", Description = "Rich Dad's Guide to Financial Freedom", Author = "Robert Toru Kiyosaki", Created = new DateTime(2000, 1, 1),
                        Genre = Genre.Legend, IsPaper = true, Languages = new[] { 1, 2, 3 }, DeliveryRequired = false
                    },
                };
                jw.Save(path, data.ToList());
            }
        }
Example #2
0
        public BookRepository()
        {
            jw = new JsonWorker();
            var fileinfo = new FileInfo(path);

            if (fileinfo.Exists)
            {
                data = jw.Load(path).ToList();
            }
            else
            {
                data = new List <Book>
                {
                    new Book {
                        Id = 1, Title = "Title1"
                    },
                    new Book {
                        Id = 2, Title = "Title2"
                    },
                    new Book {
                        Id = 3, Title = "Title3"
                    },
                };
                jw.Save(path, data.ToList());
            }
        }
 public BookRepository(IJsonWorker jsonWorker) : base()
 {
     jw   = jsonWorker;
     data = jw.Load(path).ToList();
 }