Example #1
0
        private static void AddDummyOrders(this CrUDOnlyDbContext context, List <Book> books = null)
        {
            if (books == null)
            {
                books = context.Books.ToList();
            }

            var orders = new List <Order>();
            var i      = 0;

            foreach (var usersId in DummyUsersIds)
            {
                orders.Add(BuildDummyOrder(usersId, DateTime.UtcNow.AddDays(-10), books[i++]));
                orders.Add(BuildDummyOrder(usersId, DateTime.UtcNow, books[i++]));
            }
            context.AddRange(orders);
        }
Example #2
0
        public static int SeedDatabase(this CrUDOnlyDbContext context, string dataDirectory)
        {
            if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists())
            {
                throw new InvalidOperationException("The database does not exist. If you are using Migrations then run PMC command update-database to create it");
            }

            var numBooks = context.Books.Count();

            if (numBooks == 0)
            {
                //the database is emply so we fill it from a json file
                var books = BookJsonLoader.LoadBooks(Path.Combine(dataDirectory, SeedFileSubDirectory),
                                                     SeedDataSearchName).ToList();
                context.Books.AddRange(books);
                context.SaveChanges();
                numBooks = books.Count + 1;

                context.ResetOrders(books);
            }

            return(numBooks);
        }
Example #3
0
 public AddReviewService(CrUDOnlyDbContext context)
 {
     _context = context;
 }
Example #4
0
 public BookFilterDropdownService(CrUDOnlyDbContext db)
 {
     _db = db;
 }
Example #5
0
 /// <summary>
 /// This wipes all the existing orders and creates a new set of orders
 /// </summary>
 /// <param name="context"></param>
 /// <param name="books"></param>
 public static void ResetOrders(this CrUDOnlyDbContext context, List <Book> books = null)
 {
     context.RemoveRange(context.Orders.ToList()); //remove the existing orders (the lineitems will go too)
     context.AddDummyOrders(books);                //add a dummy set of orders
     context.SaveChanges();
 }
Example #6
0
 public ChangePubDateService(CrUDOnlyDbContext context)
 {
     _context = context;
 }
Example #7
0
 public static void DevelopmentEnsureCreated(this CrUDOnlyDbContext db)
 {
     db.Database.EnsureCreated();
 }
Example #8
0
 public AddRemovePromotionService(CrUDOnlyDbContext context)
 {
     _context = context;
 }
Example #9
0
 public OrderBizLogic(CrUDOnlyDbContext context, IMailService mailService)
 {
     _context     = context ?? throw new ArgumentNullException(nameof(context));
     _mailService = mailService ?? throw new ArgumentNullException(nameof(mailService));
 }
Example #10
0
 public FilterModel(CrUDOnlyDbContext context)
 {
     _filterService = new BookFilterDropdownService(context);
 }
Example #11
0
 public ListBooksService(CrUDOnlyDbContext context)
 {
     _context = context;
 }
Example #12
0
 public CrUdOnlyController(CrUDOnlyDbContext context)
 {
     _context = context;
 }