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); }
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); }
public AddReviewService(CrUDOnlyDbContext context) { _context = context; }
public BookFilterDropdownService(CrUDOnlyDbContext db) { _db = db; }
/// <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(); }
public ChangePubDateService(CrUDOnlyDbContext context) { _context = context; }
public static void DevelopmentEnsureCreated(this CrUDOnlyDbContext db) { db.Database.EnsureCreated(); }
public AddRemovePromotionService(CrUDOnlyDbContext context) { _context = context; }
public OrderBizLogic(CrUDOnlyDbContext context, IMailService mailService) { _context = context ?? throw new ArgumentNullException(nameof(context)); _mailService = mailService ?? throw new ArgumentNullException(nameof(mailService)); }
public FilterModel(CrUDOnlyDbContext context) { _filterService = new BookFilterDropdownService(context); }
public ListBooksService(CrUDOnlyDbContext context) { _context = context; }
public CrUdOnlyController(CrUDOnlyDbContext context) { _context = context; }