Esempio n. 1
0
 public void AddProduct(Products product)
 {
     using (var customerContext = new CustomerAppContext())
     {
         customerContext.Add(product);
         customerContext.SaveChanges();
     }
 }
Esempio n. 2
0
 public List <Customers> LoginCustomer(Customers customer)
 {
     using (var customerContext = new CustomerAppContext())
     {
         var result = customerContext.Customers.Where(cust => cust.Email == customer.Email && cust.Password == customer.Password).ToList();
         return(result);
     }
 }
 public UnitOfWork()
 {
     context = new CustomerAppContext();
     context.Database.EnsureCreated();   // Auto DB Table Creation
     CustomerRepository = new CustomerRepository(context);
     OrderRepository    = new OrderRepository(context);
     AddressRepository  = new AddressRepository(context);
 }
Esempio n. 4
0
        private CustomerAppContext context;   //this represents the context of database

        public UnitOfWork()
        {
            context = new CustomerAppContext();
            //context.Database.EnsureCreated();   ---- UNCOMMENT WHEN CONNECTING WITH DATABASE
            CustomerRepository = new CustomerRepository(context);
            OrderRepository    = new OrderRepository(context);
            AddressRepository  = new AddressRepository(context);
        }
Esempio n. 5
0
 public List <Products> AllProduct(Products product)
 {
     using (var customerContext = new CustomerAppContext())
     {
         var data = customerContext.Products.Select(x => x).ToList();
         return(data);
     }
 }
Esempio n. 6
0
 public void UpdateCustomer(Customers customer)
 {
     using (var customerContext = new CustomerAppContext())
     {
         customerContext.Customers.Update(customer);
         customerContext.SaveChanges();
     }
 }
Esempio n. 7
0
        public UnitOfWork()
        {
            _context = new CustomerAppContext();

            _context.Database.EnsureCreated();
            CustomerRepository = new CustomerRepository(_context);
            OrderRepository    = new OrderRepository(_context);
            AddressRepository  = new AddressRepository(_context);
        }
Esempio n. 8
0
 public void FilterProduct(Products product)
 {
     using (var customerContext = new CustomerAppContext())
     {
         var pr = customerContext.Database.ExecuteSqlCommand("spFilterProduct @Status",
                                                             new SqlParameter("@Status", product.ProductStatus)
                                                             );
     }
 }
Esempio n. 9
0
 public void SearchProduct(Products product)
 {
     using (var customerContext = new CustomerAppContext())
     {
         var pr = customerContext.Database.ExecuteSqlCommand("spSearchProduct @Product",
                                                             new SqlParameter("@Product", product.ProductCode)
                                                             );
     }
 }
Esempio n. 10
0
 public void AddCustomer(Customers customer)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Random rand = new Random();
         customer.CustomerNumber = rand.Next();
         customerContext.Customers.Add(customer);
         customerContext.SaveChanges();
     }
 }
Esempio n. 11
0
 public void DeleteCustomer(int customerid)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Customers customer = new Customers();
         customer.CustomerId = customerid;
         customerContext.Customers.Remove(customer);
         customerContext.SaveChanges();
     }
 }
Esempio n. 12
0
 public void DeleteProduct(int productid)
 {
     using (var customerContext = new CustomerAppContext())
     {
         Products product = new Products();
         product.ProductId = productid;
         customerContext.Remove(product.ProductId);
         customerContext.SaveChanges();
     }
 }
Esempio n. 13
0
        private static ICustomerRepository GetSQLLiteRepo()
        {
            var options = new DbContextOptionsBuilder <CustomerAppContext>();

            options.UseSqlite("Data Source=customerApp.db");
            var context = new CustomerAppContext(options.Options);

            DBInitializer.SeedDB(context);
            ICustomerRepository custRepoSQLLite = new CustomerApp.Infrastructure.SQLData.Repositories.CustomerRepository(context);

            return(custRepoSQLLite);
        }
Esempio n. 14
0
        public IActionResult GetById(int CustomerId)
        {
            using (var customerContext = new CustomerAppContext())
            {
                Customers customer = new Customers();

                var result = customerContext.Customers.Where(x => x.CustomerId == customer.CustomerId);
                if (result != null)
                {
                    return(Ok(result));
                }
                else
                {
                    return(Ok("Not Found"));
                }
            }
        }
Esempio n. 15
0
        public UnitOfWork(DbOptions opt)
        {
            DbContextOptions <CustomerAppContext> options;

            if (opt.Environment == "Development" && String.IsNullOrEmpty(opt.ConnectionString))
            {
                options = new DbContextOptionsBuilder <CustomerAppContext>()
                          .UseInMemoryDatabase("TheDB")
                          .Options;
            }
            else
            {
                options = new DbContextOptionsBuilder <CustomerAppContext>()
                          .UseSqlServer(opt.ConnectionString)
                          .Options;
            }

            context = new CustomerAppContext(options);
        }
Esempio n. 16
0
 public CustomerRepository(CustomerAppContext context)
 {
     _context = context;
 }
Esempio n. 17
0
 public UnitOfWork()
 {
     context            = new CustomerAppContext();
     CustomerRepository = new CustomerRepositoryEFMemory(context);
     OrderRepository    = new OrderRepository(context);
 }
 public ProductRepository(CustomerAppContext ctx)
 {
     _ctx = ctx;
 }
 public OrderRepository(CustomerAppContext ctx)
 {
     _ctx = ctx;
 }
Esempio n. 20
0
 public FineTypeRepository(CustomerAppContext context)
 {
     _context = context;
 }
Esempio n. 21
0
 public AddressRepository(CustomerAppContext context)
 {
     _context = context;
 }
Esempio n. 22
0
 public OrderRepository(CustomerAppContext context)
 {
     this.context = context;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CustomerAppContext context)
        {
            if (env.IsDevelopment())
            {
                context.Database.EnsureCreated();   // Automatic DB Creation
                app.UseDeveloperExceptionPage();
                var facade = new BLLFacade();

                var address = facade.AddressService.Create(
                    new AddressBO()
                {
                    City   = "Kolding",
                    Street = "SesamStrasse",
                    Number = "22A"
                });
                var address2 = facade.AddressService.Create(
                    new AddressBO()
                {
                    City   = "BingoCity",
                    Street = "DingoDoiok",
                    Number = "2e2"
                });
                var address3 = facade.AddressService.Create(
                    new AddressBO()
                {
                    City   = "Hurly Smurf",
                    Street = "Trainstiik",
                    Number = "44d"
                });


                var cust = facade.CustomerService.Create(
                    new CustomerBO()
                {
                    FirstName  = "Lars",
                    LastName   = "Bilde",
                    AddressIds = new List <int>()
                    {
                        address.Id, address3.Id
                    },
                });
                facade.CustomerService.Create(
                    new CustomerBO()
                {
                    FirstName  = "Ole",
                    LastName   = "Eriksen",
                    AddressIds = new List <int>()
                    {
                        address.Id, address2.Id
                    }
                });
                for (int i = 0; i < 5; i++)
                {
                    facade.OrderService.Create(
                        new OrderBO()
                    {
                        DeliveryDate = DateTime.Now.AddMonths(1),
                        OrderDate    = DateTime.Now.AddMonths(-1),
                        CustomerId   = cust.Id
                    });
                }
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
 public UserRepository(CustomerAppContext context)
 {
     db = context;
 }