public LineItemsController(ILineItem context, ApplicationDbContext user, ProductDBContext dbContext, UserManager <ApplicationUser> userManager) { _context = context; _user = user; _dbContext = dbContext; _userManager = userManager; }
public CreateOrderHandler(ProductDBContext _dbContext, IMapper _autoMapper, IHttpContextAccessor _httpContextAccessor, ICapPublisher _capBus) { dbContext = _dbContext; autoMapper = _autoMapper; httpContextAccessor = _httpContextAccessor; capBus = _capBus; }
private void NinjaProducts(ProductDBContext context) { /* context.Products.AddOrUpdate(x => x.Description, new Product[] * { * * * new Product() * { * Description = "Wah", * QuantityInStock = 500, * UnitPrice = 200.00f, * CategoryId = 1, * SupplierId = 3 * } * });*/ // context.SaveChanges(); /**/ context.Categories.AddOrUpdate(c => c.Description, new Category[] { new Category { Description = "Bikes", productsInCategory = new Product[] { new Product { Description = "bac", QuantityInStock = 500, UnitPrice = 500f, SupplierId = 3, ProductId = 1 } } } // end-Category1 }); context.SaveChanges(); /* * */ /* * context.Products.AddOrUpdate(new Product[] * { * new Product * { * Description = "RT Crankarm", * SupplierId = 3, * CategoryId = 1, * QuantityInStock = 500, * UnitPrice = (float)200.00 * }, * }); * context.SaveChanges(); */ }
public MainWindowViewModel() { dbConnection = new DBConnection(); productRepo = new ProductRepository(); transactionRepo = new TransactionRepository(); userRepo = new UserRepository(); userDBContext = new UserDBContext(userRepo, dbConnection); productDBContext = new ProductDBContext(productRepo, dbConnection); transactionDBContext = new TransactionDBContext(transactionRepo, dbConnection); Auth.CreateInstance(userRepo); startingView = new StartingViewModel(); loginView = new LoginViewModel(); dashboardView = new DashboardViewModel(); profileView = new UserProfileViewModel(); listProdukView = new ListProductViewModel(productRepo); createProductView = new CreateProductViewModel(productRepo); createTransactionView = new CreateTransactionViewModel(transactionRepo, productRepo); editProductView = new EditProductViewModel(); transactionHistoryView = new TransactionHistoryViewModel(); registerView = new RegisterViewModel(userRepo); salesRecapView = new SalesRecapViewModel(); Mediator.Subscribe("Change View To Start", GoToStart); Mediator.Subscribe("Change View To Dashboard", GoToDasboard); Mediator.Subscribe("Change View To Profile", GoToProfile); Mediator.Subscribe("Change View To Product List", GoToProductList); Mediator.Subscribe("Change View To Create Product", GoToCreateProduct); Mediator.Subscribe("Change View To Create Transaction", GoToCreateTransaction); Mediator.Subscribe("Change View To Edit Product", GoToEditProduct); Mediator.Subscribe("Change View To Transaction History", GoToTransactionHistory); Mediator.Subscribe("Change View To Sales Recap", GoToSalesRecap); CurrentView = startingView; }
public static async Task TestDeleteBasket() { DbContextOptions <ProductDBContext> options = new DbContextOptionsBuilder <ProductDBContext>().UseInMemoryDatabase("TestDeleteBasket").Options; using (ProductDBContext context = new ProductDBContext(options)) { Basket basket = new Basket { ID = 0, UserName = "******", Subtotal = 2.00m, BasketItems = new List <BasketItem>() }; BasketService bs = new BasketService(context); context.Add(basket); context.SaveChanges(); List <Basket> baskets = await context.Baskets.ToListAsync(); Assert.Equal(2, baskets[0].Subtotal); bs.DeleteBasket(basket.ID); baskets = await context.Baskets.ToListAsync(); Assert.Empty(baskets); } }
public async void UpdateLineItemDBTest() { DbContextOptions <ProductDBContext> options = new DbContextOptionsBuilder <ProductDBContext>().UseInMemoryDatabase("UpdateLI").Options; using (ProductDBContext context = new ProductDBContext(options)) { LineItem li = new LineItem() { ID = 1, ProductID = 1, Quantity = Quantity.two }; context.LineItems.Add(li); await context.SaveChangesAsync(); LineItem found = await context.LineItems.FirstOrDefaultAsync(item => item.ID == 1); found.ProductID = 2; context.LineItems.Update(found); await context.SaveChangesAsync(); LineItem result = await context.LineItems.FirstOrDefaultAsync(item => item.ID == 1); Assert.Equal(2, result.ProductID); } }
public void Setup() { mockProductManagementContext = new Sqlite().CreateSqliteConnection(); productRepository = new ProductRepository(mockProductManagementContext); mockProductDatas = new ProductDatas(); mockUserDatas = new UserDatas(); }
public ProductRespository(ProductDBContext dbContext, IMapper mapper) { this._dbcontext = dbContext; this.mapper = mapper; SeedData(); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="_context"></param> // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ProductDBContext _context) { try { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); _context.Database.EnsureCreated(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new Exception("Error while processing your request..."); } }
public EditModel(ProductDBContext context, ApplicationDbContext userContext, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager) { _context = context; _userContext = userContext; _userManager = userManager; _signInManager = signInManager; }
// GET: Products public ActionResult Index(string searchBy, string search, int?Catagories, int?page) { ProductDBContext dbCatagory = new ProductDBContext(); ViewBag.Catagories = new SelectList(dbCatagory.Categories, "CategoryId", "CategoryName"); if (searchBy == "Name") { //if (Catagories != null) //{ var products = db.Products.Include(p => p.Category); return(View(products.Where(x => x.ProductName.StartsWith(search) && (x.PrimaryCategoryId == Catagories || Catagories == null)) .ToList().ToPagedList(page ?? 1, 50))); //} //else { // var products = db.Products.Include(p => p.Category); // return View(products.Where(x => x.ProductName.StartsWith(search) || search == null) // .ToList().ToPagedList(page ?? 1,10)); //} } else { var products = db.Products.Include(p => p.Category); return(View(products.Where(x => x.ProductDescription.StartsWith(search) && x.PrimaryCategoryId == Catagories || Catagories == null) .ToList().ToPagedList(page ?? 1, 50))); } }
public ProductController(IProductRepository productRepository, IWebHostEnvironment webHost, ProductDBContext context) { this.productRepository = productRepository; this.webHost = webHost; _context = context; }
public async void UpdateProductDBTest() { DbContextOptions <ProductDBContext> options = new DbContextOptionsBuilder <ProductDBContext>().UseInMemoryDatabase("UpdateProduct").Options; using (ProductDBContext context = new ProductDBContext(options)) { Product cat = new Product() { ID = 1, ProductName = "Cat", Description = "A kitty cat" }; context.Products.Add(cat); await context.SaveChangesAsync(); Product found = await context.Products.FirstOrDefaultAsync(item => item.ID == 1); found.ProductName = "Dog"; context.Products.Update(found); await context.SaveChangesAsync(); Product result = await context.Products.FirstOrDefaultAsync(item => item.ID == 1); Assert.Equal("Dog", result.ProductName); } }
public void GetCategories() { using (ProductDBContext db = new ProductDBContext()) { CategoryOfProducts = db.CategoryOfProducts.ToList().AsEnumerable(); } }
public List <Product> searchByAnyColumn(string queryValue) { using (ProductDBContext dbContext = new ProductDBContext()) { return(dbContext.CtProduct.Where(x => x.Id.Contains(queryValue) || x.Code.Contains(queryValue) || x.Name.Contains(queryValue)).ToList()); } }
public ProductProvider(ProductDBContext dbContext, ILogger <Db.Product> logger, IMapper mapper) { this.dbContext = dbContext; this.logger = logger; this.mapper = mapper; SeedData(); }
public OrderCreatedHandler(ProductDBContext dbContext, IBusPublisher busPublisher, ILogger <OrderCreatedHandler> logger) { _logger = logger; _dbContext = dbContext; _busPublisher = busPublisher; }
public UnitOfWork(ProductDBContext db) { if (db == null) { throw new ArgumentNullException("DB context is missing!"); } this.db = db; }
public ShoppingTrolleyControllerTest(TestFixture <Startup> fixture) { _testFixture = fixture; _productDBContext = _testFixture.CreateDbContext(); _productRepository = new ProductRepository(_productDBContext); _productService = new ProductService(_productRepository); _shoppingTrolleyService = new ShoppingTrolleyService(_productService); _shoppingTrolleyController = new(_logger, _shoppingTrolleyService); }
public ProductRepositoryTest() { var testConnection = @"Server=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Projects\GitHub\RefactorThis\RefactorThis\RefactorThis.API.Test\App_Data\Database.mdf;Integrated Security=True;"; var optionsBuilder = new DbContextOptionsBuilder <ProductDBContext>(); optionsBuilder.UseSqlServer(testConnection); context = new ProductDBContext(optionsBuilder.Options); }
public ProductDBContext CreateDbContext() { var options = new DbContextOptionsBuilder <ProductDBContext>() .UseInMemoryDatabase("eShoppingTrolley") .Options; var dbContext = new ProductDBContext(options); return(dbContext); }
public EFProviderRepository(ProductDBContext db) { if (db != null) { _db = db; } else { throw new ArgumentNullException(); } }
public static ProductDBContext GetMockedProductDbContext(string dbName) { var options = new DbContextOptionsBuilder <ProductDBContext>() .UseInMemoryDatabase(databaseName: dbName) .Options; var dbContext = new ProductDBContext(options); dbContext.Clear(); dbContext.Seed(); return(dbContext); }
public static async Task TestGetAllUserOrdersEager() { DbContextOptions <ProductDBContext> options = new DbContextOptionsBuilder <ProductDBContext>().UseInMemoryDatabase("TestGetOrdersEager").Options; using (ProductDBContext context = new ProductDBContext(options)) { Product product = new Product() { ID = 0, Sku = "Test/Sku/Test", Name = "TestProduct", Description = "TestProduct", Price = 1.00m, Image = "TestImage" }; context.Add(product); Order order = new Order { ID = 0, UserName = "******", Subtotal = 2.00m, OrderItems = new List <OrderItem>() }; context.Add(order); Order order2 = new Order { ID = 0, UserName = "******", Subtotal = 2.00m, OrderItems = new List <OrderItem>() }; context.Add(order2); OrderItem orderItem = new OrderItem { OrderID = order.ID, ProductID = product.ID, Quantity = 2, Product = product, Order = order, }; context.Add(orderItem); context.SaveChanges(); OrderService os = new OrderService(context); List <Order> test = await os.GetAllUserOrdersEager("TestOrder"); Assert.Equal(2, test[0].Subtotal); } }
public void GetCategory() { if (CategoryOfProductID > 0) { using (ProductDBContext db = new ProductDBContext()) { this.CategoryName = db.CategoryOfProducts.Find(this.CategoryOfProductID) != null? db.CategoryOfProducts.Find(this.CategoryOfProductID).Description : string.Empty; } } }
/// <summary> /// /// </summary> /// <param name="_context"></param> public UserRepository(ProductDBContext _context) { try { this._context = _context; } catch { throw; } }
public ActionResult Checkout(FormCollection collection) { /* Add your logic for handling the sending of payment to the selected payment gateway. */ ProductDBContext db = new ProductDBContext(); DeliveryDetails deldet = new DeliveryDetails(); deldet.billing_city = collection["billing_city"]; deldet.billing_country = collection["billing_country"]; deldet.billing_email = collection["billing_email"]; deldet.billing_first_name = collection["billing_first_name"]; deldet.billing_last_name = collection["billing_last_name"]; deldet.billing_notes = collection["billing_notes"]; deldet.billing_phone = collection["billing_phone"]; deldet.billing_state = collection["billing_state"]; deldet.billing_stret_1 = collection["billing_stret_1"]; deldet.billing_stret_2 = collection["billing_stret_2"]; deldet.billing_zip = collection["billing_zip"]; deldet.payment_gateway = collection["payment_gateway"]; db.DeliveryDetails.Add(deldet); CartMain main = new CartMain(); main.DeliveryDetails = deldet; main.cart_date = DateTime.Now; main.Discount = 0; db.CartMains.Add(main); CartSub sub = new CartSub(); var cart_items = db.Products.Where(item => SessionSingleton.Current.Cart.Keys.Contains(item.id)); var items = SessionSingleton.Current.Cart; foreach (var item in items) { sub = new CartSub(); var its = item.Value; JavaScriptSerializer js = new JavaScriptSerializer(); var persons = js.Deserialize <ToDoItem>(its); sub.pro_id = item.Key; sub.quantity = persons.quantity; sub.type = persons.type; sub.color = persons.selColor; db.CartSubs.Add(sub); } db.SaveChanges(); SessionSingleton.setclear(); if (deldet.payment_gateway == "paypal") { return(RedirectToAction("PaymentWithPaypal", "Cart")); } return(RedirectToAction("Cash", "Cart")); }
public IActionResult Edit(ProductsUpdate model) { var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; using (ProductDBContext dbContext = new ProductDBContext()) { MemoryStream ms = new MemoryStream(); file.OpenReadStream().CopyTo(ms); Models.Products.ProductsCreate imageEntity = new Models.Products.ProductsCreate() { Data = Convert.ToBase64String(ms.ToArray()), }; datamax = imageEntity.Data; } } } model.Data = datamax; var updateResult = false; var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://localhost:44354/api/Products/update"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "PUT"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var json = JsonConvert.SerializeObject(model); streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); updateResult = bool.Parse(result); } if (updateResult) { TempData["Message"] = "User has been update successfully"; } ViewBag.units = unit.GetUnits(); ViewBag.ProductTypes = productType.GetProductTypes(); return(RedirectToAction("Index", "Products")); }
private void CreateProducts(ProductDBContext dbContext) { for (int i = 1; i <= 5; i++) { dbContext.Products.Add(new Products.Db.Product { Id = i, Inventory = i + 10, Price = (decimal)(i * 3.14), Name = Guid.NewGuid().ToString() }); } dbContext.SaveChanges(); }
public virtual List <TEntity> GetList() { try { using (ProductDBContext dBContext = new ProductDBContext()) { return(dBContext.Set <TEntity>().ToList()); } } catch (Exception ex) { throw ex; } }