예제 #1
0
 public static void DeleteOneStore(ParknGardenData db, Store store)
 {
     if (store.ID != 0)
     {
         db.Stores.Remove(store);
         db.SaveChanges();
     }
 }
예제 #2
0
 /// <summary>
 /// A method that checks if a username is in use in the database
 /// </summary>
 /// <param name="userName">userName is the string that is used to see if it exists in the database</param>
 /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
 /// <returns>returns true if the username is in use and false if not</returns>
 public static bool CheckUserName(string userName, ParknGardenData db)
 {
     if (db.Auths.FirstOrDefault(u => u.Username == userName) == null)
     {
         return(false);
     }
     return(true);
 }
예제 #3
0
        /// <summary>
        /// Deletes session from db, with the sesseionKey specified.
        /// </summary>
        /// <param name="sessionKey">SessionKey of the session to be deleted.</param>
        /// <param name="db">DBContext to use.</param>
        /// <returns>The session that was deleted.</returns>
        public static Session DeleteSession(string sessionKey, ParknGardenData db)
        {
            Session session = db.Sessions.FirstOrDefault(s => s.SessionKey == sessionKey);

            if (session != null)
            {
                db.Sessions.Remove(session);
                db.SaveChanges();
            }
            return(session);
        }
예제 #4
0
        public static Dictionary <int, Invoice> GetAllInvoices(ParknGardenData db)
        {
            Dictionary <int, Invoice> allInvoices = new Dictionary <int, Invoice>();

            foreach (Invoice invoice in db.Invoices)
            {
                allInvoices.Add(invoice.ID, invoice);
            }

            return(allInvoices);
        }
예제 #5
0
        public static void CreateLogEntry(ParknGardenData db, int userId, string logEntry, int requestType)
        {
            Log newLog = new Log()
            {
                DateAndTime = DateTime.Now, LogEntry = logEntry, RequestType = requestType, UserID = userId
            };

            newLog.LogEntry += " at ";
            db.Logs.Add(newLog);
            db.SaveChanges();
        }
예제 #6
0
        /// <summary>
        /// Gets the user level of the user, identified by session key.
        /// </summary>
        /// <param name="sessionKey">Session key.</param>
        /// <returns>Returns int corresponding to UserLevel ID in the database.</returns>
        public static int GetUserLevel(string sessionKey, ParknGardenData db)
        {
            if (!Authenticate(sessionKey, db))
            {
                return(-1);
            }

            return(db.UserLevels.FirstOrDefault(
                       l => l.ID == db.Users.FirstOrDefault(
                           u => u.ID == db.Sessions.FirstOrDefault(
                               s => s.SessionKey == sessionKey).UserID).UserLevelID)?.ID ?? -1);
        }
예제 #7
0
        public static Dictionary <int, UserLevel> GetAllUserLevels(ParknGardenData db)
        {
            Dictionary <int, UserLevel> userLevels = new Dictionary <int, UserLevel>();

            List <UserLevel> userLevelDB = db.UserLevels.ToList();

            foreach (UserLevel userLevel in userLevelDB)
            {
                userLevels.Add(userLevel.ID, userLevel);
            }

            return(userLevels);
        }
예제 #8
0
        /// <summary>
        /// A method that gets all the roles from the database
        /// </summary>
        /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
        /// <returns>Returns a dictionary where for a specific entry the key is the roleId and the value is of type Role</returns>
        public static Dictionary <int, Role> GetAllRoles(ParknGardenData db)
        {
            Dictionary <int, Role> roles = new Dictionary <int, Role>();

            List <Role> roleDB = db.Roles.ToList();

            foreach (Role role in roleDB)
            {
                roles.Add(role.ID, role);
            }

            return(roles);
        }
예제 #9
0
        /// <summary>
        /// Method that gets all the users from the database
        /// </summary>
        /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
        /// <returns>Returns a dictionary where the key is the userId and the value is of type User for a specific value</returns>
        public static Dictionary <int, User> GetAllUsers(ParknGardenData db)
        {
            Dictionary <int, User> users = new Dictionary <int, User>();

            List <User> userDB = db.Users.ToList();

            foreach (User user in userDB)
            {
                users.Add(user.ID, user);
            }

            return(users);
        }
예제 #10
0
        public static Dictionary <int, Category> GetAllCategories(ParknGardenData db)
        {
            Dictionary <int, Category> categories = new Dictionary <int, Category>();

            List <Category> categoriesDB = db.Categories.ToList();

            foreach (Category c in categoriesDB)
            {
                categories.Add(c.ID, c);
            }

            return(categories);
        }
예제 #11
0
        public static Dictionary <int, Store> GetAllStores(ParknGardenData db)
        {
            Dictionary <int, Store> stores = new Dictionary <int, Store>();

            List <Store> storeDB = db.Stores.ToList();

            foreach (Store store in storeDB)
            {
                stores.Add(store.ID, store);
            }

            return(stores);
        }
예제 #12
0
        /// <summary>
        /// Method to get all the Suppliers from the database to a dictionary, where the key is the Supplier ID and the Value is the Supplier. It has the database sa a paramater
        /// </summary>
        /// <param name="db"> </param>
        /// <returns></returns>
        public static Dictionary <int, Supplier> GetAllSupplier(ParknGardenData db)
        {
            Dictionary <int, Supplier> suppliers = new Dictionary <int, Supplier>();

            List <Supplier> supplierDB = db.Suppliers.ToList();

            foreach (Supplier supplier in supplierDB)
            {
                suppliers.Add(supplier.ID, supplier);
            }

            return(suppliers);
        }
예제 #13
0
        public static Dictionary <int, Item> GetAllItems(ParknGardenData db)
        {
            Dictionary <int, Item> items = new Dictionary <int, Item>();

            List <Item> itemsDB = db.Items.ToList();

            foreach (Item item in itemsDB)
            {
                items.Add(item.ID, item);
            }

            return(items);
        }
예제 #14
0
        public static Dictionary <int, Salary> GetAllSalaries(ParknGardenData db)
        {
            Dictionary <int, Salary> salaries = new Dictionary <int, Salary>();

            List <Salary> userDB = db.Salaries.ToList();

            foreach (Salary salary in userDB)
            {
                salaries.Add(salary.UserID, salary);
            }

            return(salaries);
        }
예제 #15
0
        public static Dictionary <int, int> StoreHasStock(int storeID, ParknGardenData db)
        {
            Dictionary <int, int> itemsInStock = new Dictionary <int, int>();

            //List<StockHasItem> itemsDB = db.StockHasItems.Where(s => s.StockID == stockID).ToList();

            //  foreach (StockHasItem item in itemsDB)
            {
                //      itemsInStock.Add(item.ItemID, item.Amount);
            }

            return(itemsInStock);
        }
예제 #16
0
        public static Dictionary <int, Stock> GetAllStocks(ParknGardenData db)
        {
            Dictionary <int, Stock> stocks = new Dictionary <int, Stock>();

            List <Stock> stockDB = db.Stocks.ToList();

            foreach (Stock stock in stockDB)
            {
                stocks.Add(stock.ID, stock);
            }

            return(stocks);
        }
예제 #17
0
        /// <summary>
        /// A method that creates a new user in the database
        /// </summary>
        /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
        /// <param name="user">user is the user to be added to the database</param>
        /// <returns>Returns the created user in the database so that it can be used elsewhere</returns>
        public static User PostUser(ParknGardenData db, User user)
        {
            bool userEmailInUse = db.Users.Any(u => u.Email == user.Email);

            if (!userEmailInUse)
            {
                User newUser = db.Users.Add(user);
                db.SaveChanges();
                return(newUser);
            }

            user.ID = -1;
            return(user);
        }
예제 #18
0
        public static Dictionary <int, List <int> > GetAllInvoiceIDsFromStores(ParknGardenData db)
        {
            Dictionary <int, List <int> > allInvoices = new Dictionary <int, List <int> >();

            foreach (Invoice invoice in db.Invoices)
            {
                if (!allInvoices.ContainsKey(invoice.StoreID))
                {
                    allInvoices.Add(invoice.StoreID, new List <int>());
                }
                allInvoices[invoice.StoreID].Add(invoice.ID);
            }

            return(allInvoices);
        }
예제 #19
0
        /// <summary>
        /// A method that gets a dictionary of users depending on their UserLevel
        /// </summary>
        /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
        /// <param name="id">id is the userLevelId that is used to get the dictionary of users at a specific user level</param>
        /// <returns>Returns a dictionary where the key is the userId and the value is of type User for a specific value</returns>
        public static Dictionary <int, User> GetUsersByUserLevel(ParknGardenData db, int id)
        {
            Dictionary <int, User> users = new Dictionary <int, User>();

            List <User> userDB = db.Users.ToList();

            foreach (User user in userDB)
            {
                if (user.UserLevelID == id)
                {
                    users.Add(user.ID, user);
                }
            }

            return(users);
        }
예제 #20
0
        public static Dictionary <int, Dictionary <int, int> > ItemsInStock(ParknGardenData db)
        {
            Dictionary <int, Dictionary <int, int> > itemsInStock = new Dictionary <int, Dictionary <int, int> >();

            List <StockHasItem> itemsDB = db.StockHasItems.ToList();

            foreach (StockHasItem item in itemsDB)
            {
                if (!itemsInStock.ContainsKey(item.ItemID))
                {
                    itemsInStock.Add(item.ItemID, new Dictionary <int, int>());
                }
                itemsInStock[item.ItemID].Add(item.StockID, item.Amount);
            }

            return(itemsInStock);
        }
예제 #21
0
        public static Dictionary <int, Dictionary <int, int> > StockHasItems(ParknGardenData db)
        {
            Dictionary <int, Dictionary <int, int> > stockHasItems = new Dictionary <int, Dictionary <int, int> >();

            List <StockHasItem> itemsDB = db.StockHasItems.ToList();

            foreach (StockHasItem item in itemsDB)
            {
                if (!stockHasItems.ContainsKey(item.StockID))
                {
                    stockHasItems.Add(item.StockID, new Dictionary <int, int>());
                }
                stockHasItems[item.StockID].Add(item.ItemID, item.Amount);
            }

            return(stockHasItems);
        }
예제 #22
0
        /// <summary>
        /// A method for creating new roles in the database
        /// </summary>
        /// <param name="db"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static Role PostRole(ParknGardenData db, Role role)
        {
            bool checkRole(Role r) => r.Name.ToLower() == role.Name.ToLower();

            bool roleExists = db.Roles.Any(checkRole);

            if (!roleExists)
            {
                Role newRole = db.Roles.Add(role);
                db.SaveChanges();
                return(newRole);
            }

            Role returnRole = db.Roles.FirstOrDefault(checkRole);

            return(returnRole);
        }
예제 #23
0
 public static void DeleteOneSalary(ParknGardenData db, Salary salary)
 {
     db.Salaries.Remove(salary);
     db.SaveChanges();
 }
예제 #24
0
 /// <summary>
 /// A method that adds a new auth to the database
 /// </summary>
 /// <param name="auth">auth is the auth to be added to the database</param>
 /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
 public static void PostNewAuth(Auth auth, ParknGardenData db)
 {
     db.Auths.Add(auth);
 }
예제 #25
0
        public static Dictionary <int, Dictionary <int, int> > GetAllInvoicesHasItems(ParknGardenData db)
        {
            Dictionary <int, Dictionary <int, int> > allInvoices = new Dictionary <int, Dictionary <int, int> >();

            foreach (InvoiceHasItem item in db.InvoiceHasItems)
            {
                if (!allInvoices.ContainsKey(item.InvoiceID))
                {
                    allInvoices.Add(item.InvoiceID, new Dictionary <int, int>());
                }
                allInvoices[item.InvoiceID].Add(item.ItemID, item.Amount);
            }

            return(allInvoices);
        }
예제 #26
0
        /// <summary>
        /// Logs in the user based on username and password. Creates a session key in database and returns it if the authentication succeeds
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="db">DBContext to pull from.</param>
        /// <returns>Session key.</returns>
        public static (int UserID, string SessionKey) Login(string username, string password, ParknGardenData db)
        {
            string sessionKey = null;
            int    userID     = -1;

            string passwordHash = db.Auths.FirstOrDefault(u => u.Username == username)?.PasswordHash;

            userID = db.Auths.FirstOrDefault(u => u.Username == username)?.UserID ?? -1;
            if (password == passwordHash && userID != -1)
            {
                sessionKey = CreateSessionKey(sessionKeyLength);

                while (Authenticate(sessionKey, db))
                {
                    sessionKey = CreateSessionKey(sessionKeyLength);
                }

                db.Sessions.Add(new Session()
                {
                    SessionKey = sessionKey, UserID = userID
                });
                db.SaveChanges();
            }

            return(UserID : userID, SessionKey : sessionKey);
        }
예제 #27
0
 /// <summary>
 /// A method that deletes a given auth from the database
 /// </summary>
 /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
 /// <param name="auth">auth is the given auth that is to be deleted from the database</param>
 public static void DeleteUserAuth(ParknGardenData db, Auth auth)
 {
     db.Auths.Remove(auth);
     db.SaveChanges();
 }
예제 #28
0
 public static Salary GetOneSalary(int userID, ParknGardenData db)
 {
     return(db.Salaries.FirstOrDefault(s => s.UserID == userID));
 }
예제 #29
0
 /// <summary>
 /// Gets password salt stored in database, identified by username.
 /// </summary>
 /// <param name="username">Account Username.</param>
 /// <param name="db">DBContext to pull from.</param>
 /// <returns>Password Salt.</returns>
 public static string GetSalt(string username, ParknGardenData db)
 {
     return(db.Auths.FirstOrDefault(u => u.Username == username)?.PasswordSalt);
 }
예제 #30
0
        /// <summary>
        /// A method for getting the username for a specific user's userId
        /// </summary>
        /// <param name="userID">userID is an int that is used to find the username</param>
        /// <param name="db">db is the database to be passed to it of type ParknGardenData</param>
        /// <returns>returns the username of type string, if it can find one for the specified userId</returns>
        public static string GetUserName(int userID, ParknGardenData db)
        {
            var user = db.Auths.FirstOrDefault(u => u.UserID == userID);

            return(user?.Username);
        }