Example #1
0
 public void changeAdminCredit(int newCredit)
 {
     this.context = new extreemtEntities();
     user user = getLoggedUser();
     if (isAdmin(user))
     {
         this.context.Entry(user).State = System.Data.EntityState.Modified;
         user.cashBank = newCredit;
         this.context.SaveChanges();
     }
 }
Example #2
0
        public static user staticGetLoggedUser()
        {
            extreemtEntities db = new extreemtEntities();
            if (Account.isUserLogged())
            {
                int userid = int.Parse(HttpContext.Current.Session["userId"].ToString());

                try
                {
                    return db.users.Where(u => u.userId == userid).First();
                }
                catch (Exception e)
                {
                    return null;
                }
            }
            return null;
        }
Example #3
0
 public static bool usernameExisits(string username)
 {
     extreemtEntities db = new extreemtEntities();
     return (db.users.Where(u => u.username == username).Count() > 0);
 }
Example #4
0
        public Dictionary<string, List<string>> validateSignUp()
        {
            this.errors = new Dictionary<string, List<string>>();

            if (!Account.isUserLogged())
            {
                addError("user", "<p>user Not Logged</p>");
                return this.errors;
            }
            string content = this.Form["a"];

            extreemt.crypt algo = new extreemt.crypt();
            string decryptedId = algo.Decrypt(content);
            string[] user = decryptedId.Split(new char[] { '$', '$', '$' });
            int i = 0;
            while (user[i] == "")
            {
                i++;
            }
            if (user[i] != "2" && user[i] != "3")
            {

                addError("user", "<p>error</p>");
                return this.errors;
            }
            i++;
            while (user[i] == "")
            {
                i++;
            }
            if (user[i] != "left" && user[i] != "right")
            {
                addError("user", "<p>error</p>");
                return this.errors;
            }
            i++;
            while (user[i] == "")
            {
                i++;
            }
            string parentIdd = user[i];

            int parentId = int.Parse(parentIdd);

            extreemtEntities db = new extreemtEntities();
            if (db.users.Where(o => o.userId == parentId).Count() <= 0)
            {
                addError("parentId", "<p>parent don't exist<p>");
                return this.errors;
            }

            if (validateAccount.mailExisits(this.Form["mail"]))
            {
                addError("mail", "<p>Mail Exists - please choose another one</p>");
                return this.errors;

            }

            if (validateAccount.usernameExisits(this.Form["username"]))
            {
                addError("username", "<p>username Exists - please choose another one</p>");
                return this.errors;
            }

            //existance
            List<string> requiredFields = new List<string> { "mail", "title", "username", "mobile"
            ,"country","city" , "address" ,"ssn" ,"nationality"
             , "loginPassword" , "confirmLoginPassword" , "binCode"
            ,"confirmBinCode"
            };
            this.required(requiredFields);
            //length
            ////exact
            Dictionary<string, int> exactLength = new Dictionary<string, int>();
            exactLength.Add("ssn", 14);
            exactLength.Add("mobile", 11);
            if (this.Form["homephone"] != "" && this.Form["homephone"] != null)
            {
                exactLength.Add("homephone", 8);
            }
            exact(exactLength);

            ////range
            Dictionary<string, List<int>> rangeLength = new Dictionary<string, List<int>>();
            rangeLength.Add("mail", new List<int> { 5, 30 });
            rangeLength.Add("username", new List<int> { 3, 30 });

            rangeLength.Add("city", new List<int> { 3, 30 });
            rangeLength.Add("address", new List<int> { 3, 100 });
            rangeLength.Add("nationality", new List<int> { 3, 30 });
            rangeLength.Add("loginPassword", new List<int> { 5, 30 });
            rangeLength.Add("binCode", new List<int> { 5, 30 });
            range(rangeLength);

            //password

            if (tools.trimMoreThanOneSpace(this.Form["loginPassword"]) != tools.trimMoreThanOneSpace(this.Form["confirmLoginPassword"]))
                addError("confirmLoginPassword", "<p>Login password and confirm login password aren't exact</p>");

            if (tools.trimMoreThanOneSpace(this.Form["binCode"]) != tools.trimMoreThanOneSpace(this.Form["confirmBinCode"]))
                addError("confirmBinCode", "<p>Bin Code and confirm Bin code aren't exact</p>");

            //inclusion

            //pattern
            if (!validation.IsValidEmail(tools.trimMoreThanOneSpace(this.Form["mail"])))
                addError("mail", "<p>E-mail not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["username"])))
                addError("username", "<p>First Name not valid</p>");

            if (!validation.isNumeric(tools.trimMoreThanOneSpace(this.Form["mobile"])))
                addError("mobile", "<p>Mobile not valid</p>");

            if (this.Form["homephone"] != "" && this.Form["homephone"] != null)
            {
                if (!validation.isNumeric(tools.trimMoreThanOneSpace(this.Form["homephone"])))
                    addError("homephone", "<p>Home Phone not valid</p>");
            }

            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["city"])))
                addError("city", "<p>City not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["address"])))
                addError("address", "<p>Address not valid</p>");
            if (!validation.isNumeric(tools.trimMoreThanOneSpace(this.Form["ssn"])))
                addError("ssn", "<p>SSN(ID Number) not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["nationality"])))
                addError("nationality", "<p>Nationality not valid</p>");

            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["loginPassword"])))
                addError("loginPassword", "<p>Login Password not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["confirmLoginPassword"])))
                addError("confirmLoginPassword", "<p>Confirm Login Password not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["binCode"])))
                addError("binCode", "<p>Bin Code not valid</p>");
            if (!validation.isAlphaNumeric(tools.trimMoreThanOneSpace(this.Form["confirmBinCode"])))
                addError("confirmBinCode", "<p>Confirm Bin Code not valid</p>");

            return this.errors;
        }
Example #5
0
        private void UpdateParents(user user)
        {
            List<user> parents = new List<extreemt.user>();
            extreemtEntities db = new extreemtEntities();
            user parent = new user();
            while (user.position != "parent")
            {

                parent = db.users.Where(u => u.userId == user.parentUserId && u.genNumber == user.parentGenNum).First();

                if (user.position == "right")
                {
                    parent.rightInactiveCount += 3;
                }
                else if (user.position == "left")
                {
                    parent.leftInactiveCount += 3;
                }
                parents.Add(parent);
                user = new extreemt.user();
                user = parent;
            }
            foreach (user par in parents)
            {
                db.Entry(par).State = System.Data.EntityState.Modified;
            }
            db.SaveChanges();
        }
Example #6
0
 public static bool mailExisits(string mail)
 {
     extreemtEntities db = new extreemtEntities();
     return (db.users.Where(u => u.mail == mail).Count() > 0);
 }
Example #7
0
 public Account(Controllers.AccountController accountController)
 {
     // TODO: Complete member initialization
     this.accountController = accountController;
     this.context = new extreemtEntities();
 }
Example #8
0
        private void insertUser()
        {
            string content = this.accountController.Request.Form["a"];

            extreemt.crypt algo = new extreemt.crypt();
            string decryptedId = algo.Decrypt(content);
            string[] userr = decryptedId.Split(new char[] { '$', '$', '$' });
            int i = 0;
            while (userr[i] == "")
            {
                i++;
            }

            string parentGenNumber = userr[i];
            i++;
            while (userr[i] == "")
            {
                i++;
            }

            string myPos = userr[i];
            i++;
            while (userr[i] == "")
            {
                i++;
            }
            string parentIdd = userr[i];

            extreemtEntities db = new extreemtEntities();
            int parId = int.Parse(parentIdd);

            int parGenNumber = int.Parse(parentGenNumber);
            if (db.users.Where(u => u.parentUserId == parId && u.position == myPos && u.parentGenNum == parGenNumber).Count() > 0)
            {
                return;
            }
            string userId = (string)HttpContext.Current.Session["userId"];
            if (userId != null && userId != "")
            {
                int currentUserId = int.Parse(userId);
                user current = db.users.Where(u => u.userId == currentUserId && u.genNumber == 1).First();
                //current.credit -= 250;
                db.Entry(current).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                return;
            }

            if (!userHaveEnoughMoneyForRegister(this.getLoggedUser()))
            {
                Dictionary<string, List<string>> errors = new Dictionary<string, List<string>>();
                errors.Add("Parent Doesn't Have Enouph Money", new List<string> { "You Don't Have Enouph Money" });
                return;
            }

            user user = new user();
            user.mail = tools.trimMoreThanOneSpace(this.accountController.Request.Form["mail"]);
            user.title = tools.trimMoreThanOneSpace(this.accountController.Request.Form["title"]);
            user.username = tools.trimMoreThanOneSpace(this.accountController.Request.Form["username"]);
            user.mobile = tools.trimMoreThanOneSpace(this.accountController.Request.Form["mobile"]);
            user.homephone = tools.trimMoreThanOneSpace(this.accountController.Request.Form["homephone"]);
            user.country = tools.trimMoreThanOneSpace(this.accountController.Request.Form["country"]);
            user.city = tools.trimMoreThanOneSpace(this.accountController.Request.Form["city"]);
            user.address = tools.trimMoreThanOneSpace(this.accountController.Request.Form["address"]);
            user.ssn = tools.trimMoreThanOneSpace(this.accountController.Request.Form["ssn"]);
            user.nationality = tools.trimMoreThanOneSpace(this.accountController.Request.Form["nationality"]);
            user.relationship = tools.trimMoreThanOneSpace(this.accountController.Request.Form["relationship"]);
            user.loginPassword = tools.trimMoreThanOneSpace(this.accountController.Request.Form["loginPassword"]);
            user.walletPassword = tools.trimMoreThanOneSpace(this.accountController.Request.Form["binCode"]);
            user.parentUserId = int.Parse(parentIdd);
            user.position = myPos;
            user.parentGenNum = int.Parse(parentGenNumber);
            user.genNumber = 1;
            user.status = "inActive";
            user.leftActiveCount = 0;
            user.rightActiveCount = 0;
            user.rightInactiveCount = 1;
            user.leftInactiveCount = 1;
            user.registererId = int.Parse(HttpContext.Current.Session["userId"].ToString());

            user.userId = int.Parse(tools.generateRandomNumber(8));
            db.users.Add(user);

            db.SaveChanges();
            user leftUser = user;
            leftUser.parentGenNum = 1;
            leftUser.parentUserId = user.userId;
            leftUser.genNumber = 2;
            leftUser.position = "left";
            leftUser.leftInactiveCount = 0;
            leftUser.rightInactiveCount = 0;
            leftUser.status = "inActive";
            db.users.Add(leftUser);

            db.SaveChanges();
            user rightUser = user;
            rightUser.parentGenNum = 1;
            rightUser.parentUserId = user.userId;
            rightUser.genNumber = 3;
            rightUser.position = "right";
            rightUser.leftInactiveCount = 0;
            rightUser.rightInactiveCount = 0;
            rightUser.status = "inActive";
            db.users.Add(rightUser);
            db.SaveChanges();
            user parent = db.users.Where(u => u.userId == user.userId && u.genNumber == 1).First();
            this.UpdateParents(parent);
            this.cutOffCashCredit(this.getLoggedUser(), 250);
            //update parents
        }
Example #9
0
 private void cutOffCashCredit(user user, int amount)
 {
     this.context = new extreemtEntities();
     this.context.Entry(user).State = System.Data.EntityState.Modified;
     user.cashBank -= amount;
     this.context.SaveChanges();
 }
Example #10
0
        public Dictionary<string, List<string>> Login()
        {
            validateAccount va = new validateAccount(this.accountController.Request.Form);
            if (va.validateLogin().Count > 0)
                return va.validateLogin();

            extreemtEntities db = new extreemtEntities();
            int userId = int.Parse(this.accountController.Request.Form["id"]);
            string password = this.accountController.Request.Form["password"];
            if (db.users.Where(u => u.userId == userId && u.loginPassword == password).Count() <= 0)
            {
                Dictionary<string, List<string>> errors = new Dictionary<string, List<string>>();
                errors.Add("id", new List<string>() { "<p>Id or password may wrong</p>" });
                return errors;
            }
            return null;
        }
Example #11
0
 public user getUserById(int id)
 {
     extreemtEntities db = new extreemtEntities();
     if (db.users.Where(u => u.userId == id).Count() > 0)
     {
         return db.users.Where(u => u.userId == id && u.genNumber==1).First();
     }
     return null;
 }