public UserModel AddUser(UserModel userModel)
        {
            string orPass = userModel.userPassword;

            if (userModel.userLevel < 1)
            {
                userModel.userLevel = 1;
            }
            userModel.userPassword = ComputeHash.ComputeNewHash(userModel.userPassword);
            DataTable dt = new DataTable();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(UserStringsSql.AddUser(userModel));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            if (ComputeHash.ComputeNewHash(orPass).Equals(userModel.userPassword))
            {
                userModel.userPassword = orPass;
            }

            return(userModel);
        }
        public UserModel GetOneUserByLogin(string userNickName, string userPassword)
        {
            if (userNickName.Equals(""))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (userPassword.Equals(""))
            {
                throw new ArgumentOutOfRangeException();
            }

            if (!CheckStringFormat.IsBase64String(userPassword))
            {
                userPassword = ComputeHash.ComputeNewHash(userPassword);
            }
            DataTable dt        = new DataTable();
            UserModel userModel = new UserModel();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(UserStringsSql.GetOneUserByLogin(userNickName, userPassword));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            return(userModel);
        }
        public UserModel UpdateUser(UserModel userModel)
        {
            _users.ReplaceOne(u => u.userID.Equals(userModel.userID), userModel);
            UserModel user = GetOneUserByLogin(userModel.userNickName, userModel.userPassword);

            if (ComputeHash.ComputeNewHash(userModel.userPassword).Equals(user.userPassword))
            {
                user.userPassword = userModel.userPassword;
            }
            return(user);
        }
        public UserModel AddUser(UserModel userModel)
        {
            if (userModel.userLevel < 1)
            {
                userModel.userLevel = 1;
            }

            UserModel user;

            if (GlobalVariable.queryType == 0)
            {
                string userPassword2 = ComputeHash.ComputeNewHash(userModel.userPassword);
                USER   user2         = new USER
                {
                    userID        = userModel.userID,
                    userFirstName = userModel.userFirstName,
                    userLastName  = userModel.userLastName,
                    userNickName  = userModel.userNickName,
                    userPassword  = userPassword2,
                    userEmail     = userModel.userEmail,
                    userGender    = userModel.userGender,
                    userBirthDate = userModel.userBirthDate,
                    userPicture   = userModel.userPicture,
                    userLevel     = userModel.userLevel,
                };
                DB.USERS.Add(user2);
                DB.SaveChanges();
                user = GetOneUserById(user2.userID);
            }
            else
            {
                user = DB.AddUser(userModel.userID, userModel.userFirstName, userModel.userLastName, userModel.userNickName, userModel.userBirthDate, userModel.userGender, userModel.userEmail, ComputeHash.ComputeNewHash(userModel.userPassword), userModel.userPicture, userModel.userLevel).Select(u => new UserModel
                {
                    userID        = u.userID,
                    userFirstName = u.userFirstName,
                    userLastName  = u.userLastName,
                    userNickName  = u.userNickName,
                    userPassword  = u.userPassword,
                    userEmail     = u.userEmail,
                    userGender    = u.userGender,
                    userBirthDate = u.userBirthDate,
                    userPicture   = u.userPicture != null ? "/assets/images/users/" + u.userPicture : null,
                    userLevel     = u.userLevel
                }).SingleOrDefault();
            }

            if (ComputeHash.ComputeNewHash(userModel.userPassword).Equals(user.userPassword))
            {
                user.userPassword = userModel.userPassword;
            }

            return(user);
        }
        public LoginModel ReturnUserByNamePassword(LoginModel checkUser)
        {
            checkUser.userPassword = ComputeHash.ComputeNewHash(checkUser.userPassword);

            return((from user in _users.AsQueryable()
                    where user.userNickName.Equals(checkUser.userNickName)
                    where user.userPassword.Equals(checkUser.userPassword)
                    select new LoginModel
            {
                userNickName = user.userNickName,
                userLevel = user.userLevel,
                userPicture = user.userPicture != null ? "/assets/images/users/" + user.userPicture : null
            }).SingleOrDefault());
        }
        public UserModel AddUser(UserModel userModel)
        {
            if (userModel.userLevel < 1)
            {
                userModel.userLevel = 1;
            }

            _users.InsertOne(userModel);
            UserModel user = GetOneUserByLogin(userModel.userNickName, userModel.userPassword);

            if (ComputeHash.ComputeNewHash(userModel.userPassword).Equals(user.userPassword))
            {
                user.userPassword = userModel.userPassword;
            }

            return(user);
        }
        public LoginModel ReturnUserByNamePassword(LoginModel checkUser)
        {
            checkUser.userPassword = ComputeHash.ComputeNewHash(checkUser.userPassword);
            if (checkUser == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            DataTable  dt         = new DataTable();
            LoginModel loginModel = new LoginModel();

            using (SqlCommand command = new SqlCommand())
            {
                dt = GetMultipleQuery(UserStringsSql.ReturnUserByNamePassword(checkUser));
            }
            foreach (DataRow ms in dt.Rows)
            {
                loginModel = LoginModel.ToObject(ms);
            }

            return(loginModel);
        }
        public UserModel UpdateUser(UserModel userModel)
        {
            string    orPass = userModel.userPassword;
            DataTable dt     = new DataTable();

            using (MySqlCommand command = new MySqlCommand())
            {
                dt = GetMultipleQuery(UserStringsMySql.UpdateUser(userModel));
            }
            foreach (DataRow ms in dt.Rows)
            {
                userModel = UserModel.ToObject(ms);
            }

            if (ComputeHash.ComputeNewHash(orPass).Equals(userModel.userPassword))
            {
                userModel.userPassword = orPass;
            }

            return(userModel);
        }
        public UserModel GetOneUserByLogin(string userNickName, string userPassword)
        {
            if (!CheckStringFormat.IsBase64String(userPassword))
            {
                userPassword = ComputeHash.ComputeNewHash(userPassword);
            }

            if (GlobalVariable.queryType == 0)
            {
                return(DB.USERS.Where(u => u.userNickName.Equals(userNickName)).Where(u => u.userPassword.Equals(userPassword)).Select(u => new UserModel
                {
                    userID = u.userID,
                    userFirstName = u.userFirstName,
                    userLastName = u.userLastName,
                    userNickName = u.userNickName,
                    userPassword = u.userPassword,
                    userEmail = u.userEmail,
                    userGender = u.userGender,
                    userBirthDate = u.userBirthDate,
                    userPicture = u.userPicture != null ? "/assets/images/users/" + u.userPicture : null,
                    userLevel = u.userLevel
                }).SingleOrDefault());
            }
            else
            {
                return(DB.GetOneUserByLogin(userNickName, userPassword).Select(u => new UserModel
                {
                    userID = u.userID,
                    userFirstName = u.userFirstName,
                    userLastName = u.userLastName,
                    userNickName = u.userNickName,
                    userPassword = u.userPassword,
                    userEmail = u.userEmail,
                    userGender = u.userGender,
                    userBirthDate = u.userBirthDate,
                    userPicture = u.userPicture != null ? "/assets/images/users/" + u.userPicture : null,
                    userLevel = u.userLevel
                }).SingleOrDefault());
            }
        }
        public LoginModel ReturnUserByNamePassword(LoginModel checkUser)
        {
            checkUser.userPassword = ComputeHash.ComputeNewHash(checkUser.userPassword);

            if (GlobalVariable.queryType == 0)
            {
                return(DB.USERS.Where(u => u.userNickName.Equals(checkUser.userNickName)).Where(u => u.userPassword.Equals(checkUser.userPassword)).Select(u => new LoginModel
                {
                    userNickName = u.userNickName,
                    userLevel = u.userLevel,
                    userPicture = u.userPicture != null ? "/assets/images/users/" + u.userPicture : null,
                }).SingleOrDefault());
            }
            else
            {
                return(DB.ReturnUserByNamePassword(checkUser.userNickName, checkUser.userPassword).Select(u => new LoginModel
                {
                    userNickName = u.userNickName,
                    userLevel = u.userLevel,
                    userPicture = u.userPicture != null ? "/assets/images/users/" + u.userPicture : null,
                }).SingleOrDefault());
            }
        }
        public UserModel GetOneUserByLogin(string userNickName, string userPassword)
        {
            if (!CheckStringFormat.IsBase64String(userPassword))
            {
                userPassword = ComputeHash.ComputeNewHash(userPassword);
            }

            return((from user in _users.AsQueryable()
                    where user.userNickName.Equals(userNickName)
                    where user.userPassword.Equals(userPassword)
                    select new UserModel
            {
                userID = user.userID,
                userFirstName = user.userFirstName,
                userLastName = user.userLastName,
                userNickName = user.userNickName,
                userPassword = user.userPassword,
                userEmail = user.userEmail,
                userGender = user.userGender,
                userBirthDate = user.userBirthDate,
                userPicture = user.userPicture != null ? "/assets/images/users/" + user.userPicture : null,
                userLevel = user.userLevel
            }).SingleOrDefault());
        }