示例#1
0
        internal static List <Billing> GetCardsOnFileForCustomer(Customer CurrentCustomer)
        {
            List <Billing> CardOptions = new List <Billing>();

            using (var DB = new P0Context())
            {
                CustomerBillingDAO.LoadCustomersBillingList(DB);
                BillingDAO.LoadBillingList(DB);

                foreach (CustomerBilling cb in DB.CustomerBillingList)
                {
                    if (cb.CustomerID == CurrentCustomer.CustomerID)
                    {
                        foreach (Billing b in DB.BillingInformationList)
                        {
                            if (cb.BillingID == b.BillingID)
                            {
                                CardOptions.Add(b);
                            }
                        }
                    }
                }
            }
            return(CardOptions);
        }
示例#2
0
        internal static (List <Order>, List <List <OrderProducts> >, List <List <Product> >) GetOrdersInfoFromLocation(Location CurrentLocation)
        {
            List <Order> OrdersFromLocation   = new List <Order>();
            List <List <OrderProducts> > OPs  = new List <List <OrderProducts> >();
            List <List <Product> >       PIOs = new List <List <Product> >();

            using (var DB = new P0Context())
            {
                OrderDAO.LoadOrdersList(DB);
                OrdersFromLocation = DB.OrdersList.Where(o => o.LocationID == CurrentLocation.LocationID).ToList();
                OrderProductsDAO.LoadOrderProductsList(DB);
                foreach (Order order in OrdersFromLocation)
                {
                    List <OrderProducts> OrderProducts = DB.OrderProductsList.Where(o => o.OrderID == order.OrderID).ToList();
                    OPs.Add(OrderProducts);
                }
                ProductDAO.LoadProductsList(DB);
                foreach (List <OrderProducts> ops in OPs)
                {
                    List <Product> ProductsInOrder = new List <Product>();
                    foreach (OrderProducts op in ops)
                    {
                        Product p = DB.ProductsList.First(p => p.ProductID == op.ProductID);
                        ProductsInOrder.Add(p);
                    }
                    PIOs.Add(ProductsInOrder);
                }
            }
            return(OrdersFromLocation, OPs, PIOs);
        }
示例#3
0
        /// <summary>
        /// Fetches information about the Customer based on their Account Information
        /// </summary>
        /// <param name="Account"></param>
        /// <returns>A reference to the Current Customer</returns>
        internal static Customer GetCurrentCustomer(UserAccount Account)
        {
            Customer CurrentCustomer;

            using (var DB = new P0Context())
            {
                Customer customer = new Customer();

                UserAccountDAO.LoadUserAccountsList(DB);
                foreach (UserAccount a in DB.UserAccountsList)
                {
                    if (Account.Username == a.Username && Account.Password == a.Password)
                    {
                        customer.CustomerID = Account.CustomerID;
                        break;
                    }
                }

                CustomerDAO.LoadCustomersList(DB);
                foreach (Customer c in DB.CustomersList)
                {
                    if (customer.CustomerID == c.CustomerID)
                    {
                        customer.FirstName = c.FirstName;
                        customer.LastName  = c.LastName;
                        break;
                    }
                }
                CurrentCustomer = customer;
            }
            return(CurrentCustomer);
        }
示例#4
0
        internal static void PlaceOrder(List <Product> ShoppingCart, Billing BillingInfo, Customer CurrentCustomer, Location CurrentLocation, List <int> Quantities)
        {
            DateTime now = System.DateTime.Now;

            using (var DB = new P0Context())
            {
                Order Order = new Order
                {
                    CustomerID = CurrentCustomer.CustomerID,
                    LocationID = CurrentLocation.LocationID,
                    OrderTime  = now.ToString()
                };
                OrderDAO.AddOrders(Order, DB);
                LocationProductsDAO.LoadLocationProductsList(DB);
                foreach (Product p in ShoppingCart)
                {
                    int           QuantityIndex = ShoppingCart.IndexOf(p);
                    OrderProducts OP            = new OrderProducts
                    {
                        OrderID   = Order.OrderID,
                        ProductID = p.ProductID,
                        Quantity  = Quantities[QuantityIndex]
                    };
                    OrderProductsDAO.AddOrderProducts(OP, DB);
                    LocationProducts LP = DB.LocationProductsList.Single(
                        x => (x.LocationID == CurrentLocation.LocationID && x.ProductID == p.ProductID));
                    LP.Inventory -= OP.Quantity;
                    LocationProductsDAO.UpdateLocationProducts(LP, DB);
                }
            }
        }
示例#5
0
        internal static List <Product> FindProductsOfTypeFromStore(string Type, Location CurrentLocation)
        {
            List <Product> ProductsOfType = new List <Product>();

            using (var DB = new P0Context())
            {
                ProductDAO.LoadProductsList(DB);
                LocationProductsDAO.LoadLocationProductsList(DB);

                foreach (LocationProducts lp in DB.LocationProductsList)
                {
                    if (lp.LocationID == CurrentLocation.LocationID)
                    {
                        foreach (Product p in DB.ProductsList)
                        {
                            if (p.Type + " FROM STORE" == Type && lp.ProductID == p.ProductID)
                            {
                                ProductsOfType.Add(p);
                            }
                        }
                    }
                }
            }
            return(ProductsOfType);
        }
示例#6
0
 /// <summary>
 /// Creates a new entries in the Customers Table and UserAccounts Table for new Users
 /// </summary>
 /// <param name="Account"></param>
 public static void RegisterAccount(UserAccount Account, Customer c)
 {
     using (var DB = new P0Context())
     {
         CustomerDAO.AddCustomer(c, DB);
         Account.Customer = c;
         UserAccountDAO.AddUserAccount(Account, DB);
     }
 }
示例#7
0
        internal static Location GetOrderLocation(Order o)
        {
            Location Location;

            using (var DB = new P0Context())
            {
                LocationDAO.LoadLocationsList(DB);
                Location = DB.LocationList.First(l => l.LocationID == o.LocationID);
            }
            return(Location);
        }
示例#8
0
        internal static List <Location> GetAllLocations()
        {
            List <Location> LocationList;

            using (var DB = new P0Context())
            {
                LocationDAO.LoadLocationsList(DB);
                LocationList = DB.LocationList;
            }
            return(LocationList);
        }
示例#9
0
        internal static List <Product> GetAllProducts()
        {
            List <Product> ProductList;

            using (var DB = new P0Context())
            {
                ProductDAO.LoadProductsList(DB);
                ProductList = DB.ProductsList;
            }
            return(ProductList);
        }
示例#10
0
        internal static List <Customer> GetAllCustomers()
        {
            List <Customer> CustomerList = new List <Customer>();

            using (var DB = new P0Context())
            {
                CustomerDAO.LoadCustomersList(DB);
                CustomerList = DB.CustomersList;
            }
            return(CustomerList);
        }
示例#11
0
 internal static void AddNewCardInformationToUser(Billing CardInfoEntered, Customer CurrentCustomer)
 {
     using (var DB = new P0Context())
     {
         BillingDAO.AddBilling(CardInfoEntered, DB);
         CustomerBilling CB = new CustomerBilling
         {
             CustomerID = CurrentCustomer.CustomerID,
             BillingID  = CardInfoEntered.BillingID
         };
         CustomerBillingDAO.AddCustomerBilling(CB, DB);
     }
 }
示例#12
0
        internal static List <int> FindLocationIDsWithProduct(Product ProductToBuy)
        {
            List <int> LocationIDs = new List <int>();

            using (var DB = new P0Context())
            {
                LocationProductsDAO.LoadLocationProductsList(DB);
                foreach (LocationProducts lp in DB.LocationProductsList)
                {
                    if (ProductToBuy.ProductID == lp.ProductID)
                    {
                        LocationIDs.Add(lp.LocationID);
                    }
                }
            }
            return(LocationIDs);
        }
示例#13
0
        internal static int FindNumInStockAtLocation(Product ProductToBuy, Location CurrentLocation)
        {
            int InStock = 0;

            using (var DB = new P0Context())
            {
                LocationProductsDAO.LoadLocationProductsList(DB);
                foreach (LocationProducts LP in DB.LocationProductsList)
                {
                    if (LP.LocationID == CurrentLocation.LocationID && LP.ProductID == ProductToBuy.ProductID)
                    {
                        InStock = LP.Inventory;
                        break;
                    }
                }
            }
            return(InStock);
        }
示例#14
0
        /// <summary>
        /// Takes in the Login Information and verifies that the user exits
        /// </summary>
        /// <param name="Account"></param>
        /// <returns>True if user exists, false if username or password doesn't match</returns>
        internal static bool LoginSuccesful(UserAccount Account)
        {
            bool success = false;

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                foreach (UserAccount a in DB.UserAccountsList)
                {
                    if (Account.Username == a.Username && Account.Password == a.Password)
                    {
                        Account.CustomerID = a.CustomerID;
                        success            = true;
                        break;
                    }
                }
            }
            return(success);
        }
示例#15
0
        internal static List <Location> FindLocationsWithProduct(Product ProductToBuy, List <int> LocationIDs)
        {
            List <Location> StoreOptions = new List <Location>();

            using (var DB = new P0Context())
            {
                LocationDAO.LoadLocationsList(DB);
                foreach (int LocationID in LocationIDs)
                {
                    foreach (Location l in DB.LocationList)
                    {
                        if (LocationID == l.LocationID)
                        {
                            StoreOptions.Add(l);
                        }
                    }
                }
            }
            return(StoreOptions);
        }
示例#16
0
        public void CreateAccountShouldAdd1UserAccount()
        {
            UserAccount U = new UserAccount
            {
                Username = "******",
                Password = "******"
            };

            Customer C = new Customer
            {
                FirstName = "Paul",
                LastName  = "Wall"
            };

            int numC;
            int numU;
            int nC;
            int nU;

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                numU = DB.UserAccountsList.Count;
                numC = DB.CustomersList.Count;
            }

            DatabaseControl.RegisterAccount(U, C);

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                nU = DB.UserAccountsList.Count - 1;
                nC = DB.CustomersList.Count - 1;
            }

            Assert.Equal(numU, nU);
        }
示例#17
0
        public void CreateAccountShouldAdd1Customer()
        {
            UserAccount U = new UserAccount
            {
                Username = "******",
                Password = "******"
            };

            Customer C = new Customer
            {
                FirstName = "Statyve",
                LastName  = "Thomas"
            };

            int numC;
            int numU;
            int nC;
            int nU;

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                numU = DB.UserAccountsList.Count;
                numC = DB.CustomersList.Count;
            }

            DatabaseControl.RegisterAccount(U, C);

            using (var DB = new P0Context())
            {
                UserAccountDAO.LoadUserAccountsList(DB);
                CustomerDAO.LoadCustomersList(DB);
                nU = DB.UserAccountsList.Count - 1;
                nC = DB.CustomersList.Count - 1;
            }

            Assert.Equal(numC, nU);
        }
        static void Main(string[] args)
        {
            //logger configuration
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.File("../Logs.json")
                         .CreateLogger();

            /*
             * Log.Verbose("Verbose log message");
             * Log.Debug("Debug log message");
             * Log.Information("Information log message");
             * Log.Warning("Warning log message");
             * Log.Error("Error log message");
             * Log.Fatal("Fatal log message");
             */

            //get the config file
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            //set up db connection
            string connectionString = configuration.GetConnectionString("P0DB-REAL");
            DbContextOptions <P0Context> options = new DbContextOptionsBuilder <P0Context>()
                                                   .UseSqlServer(connectionString)
                                                   .Options;

            //using statement
            using var context = new P0Context(options);

            IMapper shopMapper = new ShopMapper();

            IMenu menu = new MainMenu(new CustomerBL(new CustomerRepoDB(context, shopMapper)), new ProductBL(new ProductRepoDB(context, shopMapper)), new LocationBL(new LocationRepoDB(context, shopMapper)), new InventoryBL(new InventoryRepoDB(context, shopMapper)), new OrderBL(new OrderRepoDB(context, shopMapper)), new CartBL(new CartRepoDB(context, shopMapper)), new CartProductsBL(new CartProductsRepoDB(context, shopMapper)), new OrderItemsBL(new OrderItemRepoDB(context, shopMapper)));

            menu.Start();
        }
 public static void LoadUserAccountsList(P0Context DB)
 {
     DB.UserAccountsList = DB.UserAccounts.ToList();
 }
 internal static void RemoveUserAccount(UserAccount user, P0Context DB)
 {
     DB.UserAccounts.Remove(user);
     DB.SaveChanges();
 }
 internal static void UpdateUserAccount(UserAccount user, P0Context DB)
 {
     DB.UserAccounts.Update(user);
     DB.SaveChanges();
 }
 public static void AddUserAccount(UserAccount user, P0Context DB)
 {
     DB.UserAccounts.Add(user);
     DB.SaveChanges();
 }
示例#23
0
 internal static void AddOrders(Order o, P0Context DB)
 {
     DB.Orders.Add(o);
     DB.SaveChanges();
 }
示例#24
0
 internal static void LoadDefaultLocationsList(P0Context DB)
 {
     DB.DefaultLocationList = DB.DefaultLocations.ToList();
 }
示例#25
0
 internal static void RemoveOrders(Order o, P0Context DB)
 {
     DB.Orders.Remove(o);
     DB.SaveChanges();
 }
示例#26
0
 internal static void UpdateDefaultLocation(DefaultLocation dl, P0Context DB)
 {
     DB.DefaultLocations.Update(dl);
     DB.SaveChanges();
 }
示例#27
0
 internal static void UpdateOrders(Order o, P0Context DB)
 {
     DB.Orders.Update(o);
     DB.SaveChanges();
 }
示例#28
0
 internal static void RemoveDefaultLocation(DefaultLocation dl, P0Context DB)
 {
     DB.DefaultLocations.Remove(dl);
     DB.SaveChanges();
 }
示例#29
0
 internal static void LoadOrdersList(P0Context DB)
 {
     DB.OrdersList = DB.Orders.ToList();
 }
示例#30
0
 internal static void AddDefaultLocation(DefaultLocation dl, P0Context DB)
 {
     DB.DefaultLocations.Add(dl);
     DB.SaveChanges();
 }