static void Main(string[] args) { //get the config file var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); //Setting up db connection string connectionString = configuration.GetConnectionString("StoreDB"); DbContextOptions <StoreDBContext> options = new DbContextOptionsBuilder <StoreDBContext>().UseSqlServer(connectionString).Options; //using statement used to dispose of the context when its no longer used using var context = new StoreDBContext(options); IMenu menu = new StoreFrontMenu(new ManagerBL(new ManagerRepoDB(context, new ManagerMapper())), new CustomerBL(new CustomerRepoDB(context, new CustomerMapper())), new LocationBL(new LocationRepoDB(context, new LocationMapper())), new ProductBL(new ProductRepoDB(context, new ProductMapper())), new InventoryLineItemBL(new InventoryLineItemRepoDB(context, new InventoryLineItemMapper())), new CustomerCartBL(new CustomerCartRepoDB(context, new CustomerCartMapper())), new CustomerOrderLineItemBL(new CustomerOrderLineItemRepoDB(context, new CustomerOrderLineItemMapper())), new CustomerOrderHistoryBL(new CustomerOrderHistoryRepoDB(context, new CustomerOrderHistoryMapper()))); menu.Start(); }
static void Main(string[] args) { //config file var configuation = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); //set up DB connection string connectionString = configuation.GetConnectionString("StoreDB"); DbContextOptions <StoreDBContext> options = new DbContextOptionsBuilder <StoreDBContext>() .UseSqlServer(connectionString) .Options; using var context = new StoreDBContext(options); var log = new LoggerConfiguration() //.WriteTo.Console() .WriteTo.File("../logs/Main.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); // Log.Logger = new LoggerConfiguration IMenu menuLogIn = new LogIn(new PartsBL(new StoreRepoDB(context, new StoreMapper()))); menuLogIn.Start(); }
public void AddManagerShouldAddManager() { using (var context = new StoreDBContext(options)) { IManagerRepository _repo = new ManagerRepoDB(context); _repo.AddManager ( new Model.Manager { Id = 2, ManagerName = "Batman", ManagerEmail = "*****@*****.**", ManagerPasswordHash = "Pa55WordI23", ManagerPhone = "7948062079", ManagerLocId = 1 } ); } //use the context to check the state of the db directly when asserting. using (var assertContext = new StoreDBContext(options)) { var result = assertContext.Managers.FirstOrDefault(manager => manager.ManagerName == "Batman"); Assert.NotNull(result); Assert.Equal("Batman", result.ManagerName); } }
private void Seed() { using (var context = new StoreDBContext(options)) { //This makes sure that the state of the db gets recreated every time to maintain the modularity of the tests. context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Products.AddRange ( new Product { Id = 1, ProdName = "bProduct", ProdPrice = 24, ProdCategory = (Category)4, ProdBrandName = "bBrand", Description = "Pending", }, new Product { Id = 2, ProdName = "aProduct", ProdPrice = 420, ProdCategory = (Category)2, ProdBrandName = "aBrand", Description = "Pending", } ); context.SaveChanges(); } }
public Library.Store GetInventory(int id) { using var context = new StoreDBContext(_contextOptions); // include the products and the prices in inventory var dbInventory = context.Inventories .Include(i => i.Product) .ThenInclude(i => i.Prices); // initialize a store with an id number var store = new Library.Store(id); // look inside dbinventory foreach (var inventory in dbInventory) { // wont let me do .First i'll have to ask nick why if (inventory.StoreId == id) { // turn the price datatype to a list var PriceList = inventory.Product.Prices.ToList(); // should grab the newest price in price list var price = PriceList[PriceList.Count - 1].Price1; // add to the Inventory class store.AddInventory(new Library.Product(inventory.Product.ProductId, inventory.Product.Name, (int)inventory.Quantity, (double)price)); } } // return this mess. return(store); }
public UnitOfWork(StoreDBContext _dbContext) { this.dbContext = _dbContext; //Inject Product ProductRepository = new ProductRepository(dbContext); }
public Library.DataBase GetOrder(int id) { using var context = new StoreDBContext(_contextOptions); var dbOrderHitory = context.CustomerOrders.Include(c => c.ProductOrdereds) .ThenInclude(c => c.Product) .ThenInclude(c => c.Prices); var db = new Library.DataBase(new Library.Store(id)); foreach (var orders in dbOrderHitory) { if (orders.TransactionNumber == id) { var x = orders.TransactionTime.ToString(); Library.Order order = new Library.Order(id, orders.StoreId, orders.CustomerId, x); foreach (var item in orders.ProductOrdereds) { var price = item.Product.Prices.ToList(); var tPrice = price[0].Price1; order.addItem(new Library.Product(item.ProductId, item.Product.Name, (int)item.Quantity, (double)tPrice)); } db.AddOrder(order); } } return(db); }
private void Seed() { using (var context = new StoreDBContext(options)) { //This makes sure that the state of the db gets recreated every time to maintain the modularity of the tests. context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Customers.AddRange ( new Customer { Id = 1, CustomerName = "Aquaman", CustomerEmail = "*****@*****.**", CustomerPasswordHash = "PassW0rd12E", CustomerPhone = "9702608497", CustomerAddress = "a street, a city, a state zipcode" }, new Customer { Id = 2, CustomerName = "Batman", CustomerEmail = "*****@*****.**", CustomerPasswordHash = "Pa55WordI23", CustomerPhone = "7948062079", CustomerAddress = "Batstreet, Batcity, Batstate Batcode" } ); context.SaveChanges(); } }
public AddProduct(StoreDBContext dBContext) { this.dbContext = dBContext; InitializeComponent(); TypeBox.ItemsSource = dBContext.ProductTypes.Select(x => x.Name).ToList(); TypeBox.SelectedItem = TypeBox.Items[0]; }
public void AddCustomerShouldAddCustomer() { using (var context = new StoreDBContext(options)) { ICustomerRepository _repo = new CustomerRepoDB(context); _repo.AddCustomer ( new Model.Customer { Id = 2, CustomerName = "Batman", CustomerEmail = "*****@*****.**", CustomerPasswordHash = "Pa55WordI23", CustomerPhone = "7948062079", CustomerAddress = "Batstreet, Batcity, Batstate Batcode" } ); } //use the context to check the state of the db directly when asserting. using (var assertContext = new StoreDBContext(options)) { var result = assertContext.Customers.FirstOrDefault(customer => customer.CustomerName == "Batman"); Assert.NotNull(result); Assert.Equal("Batman", result.CustomerName); } }
public Products(StoreDBContext dBContext) { this.dBContext = dBContext; InitializeComponent(); GetProducts(); }
public StoreRepository() { if (this.storeDBContext == null) { storeDBContext = new StoreDBContext(); } }
public OrderService(ShoppingCartService shoppingCartService, StoreDBContext storeDBContext, UserManager <User> userManager) { _shoppingCartService = shoppingCartService; _storeDbContext = storeDBContext; _userManager = userManager; }
[Fact] //test8 public void RemoveOrderFromDB() { #region Arrange //Arrange -- create an object to configure in-memory DB var options = new DbContextOptionsBuilder <StoreDBContext>() .UseInMemoryDatabase(databaseName: "RemoveOrderFromDB") .Options; #endregion #region Act-Assert //Act using (var db = new StoreDBContext(options)) { Order order = new Order { CustomerId = 1, LocationId = 1, TimeStamp = "1230", Total = 50 }; db.Add(order); db.SaveChanges(); #region Assert Assert.Equal(1, db.Order.Count()); db.Remove(order); db.SaveChanges(); Assert.Equal(0, db.Order.Count()); #endregion //end assert }; #endregion //end act }
public async Task Store_Inserts() { using var connection = new SqliteConnection("Data Source=:memory:"); var options = new DbContextOptionsBuilder <StoreDBContext>().UseSqlite(connection).Options; connection.Open(); // set up customer var custTest = new StoreApp.DataAccess.BusinessModels.Customer(); custTest.Email = "g"; custTest.FirstName = "J"; custTest.FirstName = "g"; custTest.Phone = "123245"; // call the database and save using (var context = new StoreDBContext(options)) { context.Database.EnsureCreated(); _repository = new StoreRepository(context); // act await _repository.AddCustomer(custTest); } //set up db again using var context2 = new StoreDBContext(options); var customer = await context2.Customers.Include(l => l.CustomerId == 1).ToListAsync(); Assert.Equal(0, customer[0].CustomerId); }
public Bills(StoreDBContext dBContext) { this.dBContext = dBContext; InitializeComponent(); GetBills(); }
public void AddProductShouldAddProduct() { using (var context = new StoreDBContext(options)) { IProductRepository _repo = new ProductRepoDB(context); _repo.AddProduct ( new Model.Product { Id = 2, ProdName = "aProduct", ProdPrice = 420, ProdCategory = (Category)2, ProdBrandName = "aBrand", Description = "Pending", } ); } //use the context to check the state of the db directly when asserting. using (var assertContext = new StoreDBContext(options)) { var result = assertContext.Products.FirstOrDefault(product => product.ProdName == "aProduct"); Assert.NotNull(result); Assert.Equal("aProduct", result.ProdName); } }
public AccountController(IAccountService acc, IHttpContextAccessor httpContext, IEmailSender email, StoreDBContext context) { _acc = acc; _httpContext = httpContext; ViewBag.activeUser = httpContext.HttpContext.Request.Cookies["login_user"]; _email = email; _context = context; }
public BillWindow(ObservableCollection <CheckoutProductViewModel> ProductsList, StoreDBContext dBContext, Sale sale) { this.sale = sale; this.ProductsList = ProductsList; this.dBContext = dBContext; InitializeComponent(); ProductsListGrid.ItemsSource = this.ProductsList; }
public UserController(UserManager <User> userManager, SignInManager <User> signInManager, StoreDBContext context) { this.userManager = userManager; this.signInManager = signInManager; this.context = context; }
public HomeController(IProductService products, StoreDBContext context, IHttpContextAccessor httpContext, IAccountService accounts) { _products = products; _context = context; _httpContext = httpContext; _accounts = accounts; ViewBag.activeUser = httpContext.HttpContext.Request.Cookies["login_user"]; }
public void GetLocationsShouldReturnAllLocations() { using (var context = new StoreDBContext(options)) { IStoreRepository _repo = new StoreRepoDB(context); var locations = _repo.GetLocations(); Assert.Equal(5, locations.Count); } }
public void GetProductsShouldGetAllProducts() { using (var context = new StoreDBContext(options)) { IStoreRepository _repo = new StoreRepoDB(context); var products = _repo.GetProducts(); Assert.Equal(15, products.Count); } }
public void GetInventoriesShouldGetAllInventories() { using (var context = new StoreDBContext(options)) { IStoreRepository _repo = new StoreRepoDB(context); var inventories = _repo.GetInventory(); Assert.Equal(42, inventories.Count); } }
public void GetCustomersShouldReturnAllCustomers() { using (var context = new StoreDBContext(options)) { IStoreRepository _repo = new StoreRepoDB(context); var customers = _repo.GetCustomers(); Assert.Equal(2, customers.Count); } }
public void DeleteProduct(int index) { ProductRepository rep = new ProductRepository(); StoreDBContext db = new StoreDBContext(); Product product = rep.GetProduct(index); db.Products.Remove(product); db.SaveChanges(); }
public BaseResponse SaveOrder(Shipment shipment) { var response = new BaseResponse(); using (var dBContext = new StoreDBContext()) { using (var transaction = dBContext.Database.BeginTransaction()) { try { var cartDetail = dBContext.CartDetail.Include(x => x.Product) .Where(c => c.CartId == shipment.CartId).ToList(); var Order = new Order { OrderTotal = cartDetail.Sum(x => x.Product.Price * x.Quantity), CreateDate = DateTime.Now, Username = shipment.UserName }; dBContext.Order.Add(Order); dBContext.SaveChanges(); foreach (var item in cartDetail) { var orderDetail = new OrderDetail { ProductId = item.ProductId ?? 0, Quantity = item.Quantity ?? 0, Price = item.Product.Price, OrderId = Order.OrderId }; dBContext.OrderDetail.Add(orderDetail); dBContext.SaveChanges(); } shipment.ShipmentDate = DateTime.Now; dBContext.Shipment.Add(shipment); dBContext.SaveChanges(); dBContext.CartDetail.RemoveRange(cartDetail); dBContext.SaveChanges(); Cart cart = dBContext.Cart.Where(x => x.CartId == shipment.CartId).FirstOrDefault(); dBContext.Cart.Remove(cart); dBContext.SaveChanges(); transaction.Commit(); response.status = true; return(response); } catch (Exception ex) { transaction.Rollback(); response.status = false; response.message = ex.ToString(); return(response); } } } }
public HomeController(StoreDBContext db, IHttpContextAccessor httpContextAccessor, SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager) { this.db = db; this._httpContextAccessor = httpContextAccessor; this._userManager = userManager; this._signInManager = signInManager; }
static void Main(string[] args) { var context = new StoreDBContext(); context.Database.Initialize(true); //1. Local Store //2. Local Store Improvement //Sample Data is in The Initializer //When the model is changed it drops and remakes the DB with the seed data }
public static string BillNumber(StoreDBContext dBContext) { var number = ""; do { number = GenerateRandomNumber(); } while (dBContext.Bills.Select(b => b.Number).Contains(number)); return(number); }