Ejemplo n.º 1
0
        public void StoreAddOneCustomer(string storeLoc, CCustomer customer)
        {
            using var context = new Project0databaseContext(_contextOptions);
            // only have this part below in the data model, rest moves to console main
            var newCustomer = new Customer
            {
                Customerid  = customer.Customerid,
                Firstname   = customer.FirstName,
                Lastname    = customer.LastName,
                Phonenumber = customer.PhoneNumber,
                Email       = customer.Email,
            };

            context.Customers.Add(newCustomer);
            context.SaveChanges();

            // many to many, bridge table gets updated as well
            var newBridge = new Storecustomer
            {
                Storeloc   = storeLoc,
                Customerid = customer.Customerid
            };

            context.Storecustomers.Add(newBridge);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        // Multi-purpsoe
        public void CustomerPlaceOneOrder(COrder order, CStore store, double totalCost)
        {
            using var context = new Project0databaseContext(_contextOptions);
            // update order
            var newOrder = new Orderr
            {
                Orderid     = order.Orderid,
                Storeloc    = order.StoreLocation.Storeloc,
                Customerid  = order.Customer.Customerid,
                Orderedtime = DateTime.Now,
                Totalcost   = totalCost
            };

            context.Orderrs.Add(newOrder);
            context.SaveChanges();

            // update Orderproduct
            foreach (var product in order.ProductList)
            {
                var newOP = new Orderproduct
                {
                    Orderid   = order.Orderid,
                    Productid = product.UniqueID,
                    Quantity  = product.Quantity
                };
                context.Orderproducts.Add(newOP);
            }
            context.SaveChanges();

            var dbStore = context.Stores.Include(x => x.Inventories)
                          .FirstOrDefault(x => x.Storeloc == order.StoreLocation.Storeloc);

            // if (dbStore == null) return null;
            // update inventory quantity
            foreach (var product in order.ProductList)
            {
                foreach (var dbProd in dbStore.Inventories)
                {
                    if (product.UniqueID == dbProd.Productid)
                    {
                        dbProd.Quantity = store.Inventory[product.UniqueID].Quantity;
                    }
                }
            }
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public void DelelteOneCredential(string email)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var dbCredential = context.Credentials.FirstOrDefault(x => x.Email == email);

            if (dbCredential != null)
            {
                context.Credentials.Remove(dbCredential);
                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void DeleteOneCustomer(string storeLoc, string customerID)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var dbBridge = context.Storecustomers.FirstOrDefault(x => x.Storeloc == storeLoc && x.Customerid == customerID);

            if (dbBridge != null)
            {
                context.Storecustomers.Remove(dbBridge);
                context.SaveChanges();
            }

            var dbCustomer = context.Customers.FirstOrDefault(x => x.Customerid == customerID);

            if (dbCustomer != null)
            {
                context.Customers.Remove(dbCustomer);
                context.SaveChanges();
            }
            // null references handled in the view layer
        }
Ejemplo n.º 5
0
        public void DeleteOneProduct(string storeLoc, string productID)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var dbBridge = context.Inventories.FirstOrDefault(x => x.Storeloc == storeLoc && x.Productid == productID);

            if (dbBridge != null)
            {
                context.Inventories.Remove(dbBridge);
                context.SaveChanges();
            }

            var dbProduct = context.Products.FirstOrDefault(x => x.Productid == productID);

            if (dbProduct != null)
            {
                context.Products.Remove(dbProduct);
                context.SaveChanges();
            }
            // null references handled in the view layer
        }
Ejemplo n.º 6
0
        // Delete methods
        public void DeleteOneStore(string storeLoc)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var dbStore = context.Stores.FirstOrDefault(x => x.Storeloc == storeLoc);

            if (dbStore != null)
            {
                context.Stores.Remove(dbStore);
                context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public void AddOneCredential(CCredential credential)
        {
            using var context = new Project0databaseContext(_contextOptions);
            Credential cCredential = new Credential
            {
                Email    = credential.Email,
                Password = credential.Password
            };

            context.Credentials.Add(cCredential);
            context.SaveChanges();
        }
Ejemplo n.º 8
0
        // add methods
        public void AddOneStore(CStore store)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var newStore = new Store
            {
                Storeloc   = store.Storeloc,
                Storephone = store.Storephone
            };

            context.Stores.Add(newStore);
            context.SaveChanges();
        }
Ejemplo n.º 9
0
        // Edit methods
        public void EditOneProduct(string storeLoc, CProduct product, int quantity)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var dbBridge = context.Inventories.FirstOrDefault(x => x.Storeloc == storeLoc && x.Productid == product.UniqueID);

            if (dbBridge != null)
            {
                dbBridge.Quantity = quantity;
                context.SaveChanges();
            }


            var dbProduct = context.Products.FirstOrDefault(x => x.Productid == product.UniqueID);

            if (dbProduct != null)
            {
                dbProduct.Productid = product.UniqueID;
                dbProduct.Name      = product.Name;
                dbProduct.Category  = product.Category;
                dbProduct.Price     = product.Price;
                context.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public void AddOneProduct(CProduct product)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var newProduct = new Product
            {
                Productid = product.UniqueID,
                Name      = product.Name,
                Category  = product.Category,
                Price     = product.Price
            };

            context.Products.Add(newProduct);
            context.SaveChanges();
        }
Ejemplo n.º 11
0
        public void AddOneCustomer(CCustomer customer)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var newCustomer = new Customer
            {
                Customerid  = customer.Customerid,
                Firstname   = customer.FirstName,
                Lastname    = customer.LastName,
                Phonenumber = customer.PhoneNumber,
                Email       = customer.Email
            };

            context.Customers.Add(newCustomer);
            context.SaveChanges();
        }
Ejemplo n.º 12
0
        // Add methods
        public void StoreAddOneProduct(string storeLoc, CProduct product, int quantity)
        {
            using var context = new Project0databaseContext(_contextOptions);
            var newProduct = new Product
            {
                Productid = product.UniqueID,
                Name      = product.Name,
                Category  = product.Category,
                Price     = product.Price,
            };

            context.Products.Add(newProduct);
            context.SaveChanges();

            var newBridge = new Inventory
            {
                Storeloc  = storeLoc,
                Productid = product.UniqueID,
                Quantity  = quantity,
            };

            context.Inventories.Add(newBridge);
            context.SaveChanges();
        }