public ActionResult isExistEmployeeNumber()
 {
     string employee_number = Common.doPost("employee_number");
     string id = Common.doPost("id");
     Member _member = new Member("users");
     return Content(_member.isExist(employee_number, "employee_number", String.IsNullOrWhiteSpace(id) ? "" : "id != '" + id + "'") ? "false" : "true");
 }
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string name = Common.doPost("name");
            string type_id = Common.doPost("type_id2");
            string user_group = Common.doPost("user_group");
            string center = Common.doPost("center");
            string grade = Common.doPost("grade2");
            string employee_number = Common.doPost("employee_number");
            string username = Common.doPost("username");
            string oldpassword = Common.doPost("oldpassword");
            string password = Common.doPost("password");
            string password2 = Common.doPost("password2");
            string country_id = Common.doPost("country_id2");
            string phone_number = Common.doPost("phone_number");
            string email = Common.doPost("email");
            string status = Common.doPost("status2");
            string oper = Common.doPost("oper");
            string encryptedOldPassword = "";
            string encryptedOldPasswordDB = "";
            Member _member = new Member("users");
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });

                    if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2))
                    {
                        int userID =  Convert.ToInt32(id);
                        encryptedOldPasswordDB = (from u in this._db.recsys_users
                                                  where u.id == userID
                                                  select u.password).FirstOrDefault();
                        string salt = encryptedOldPasswordDB.Substring(0, 20);
                        encryptedOldPassword = _member.encrypt(oldpassword, salt);
                        if (!encryptedOldPassword.Equals(encryptedOldPasswordDB))
                            return Content("oldPasswordNotMatch");
                    }
                }
                _val.val(name, "req");
                _val.val(type_id, new String[] { "req", "int" });
                _val.val(user_group, new String[] { "req", "int", "get=0" });
                _val.val(center, new String[] { "req", "int" });
                _val.val(country_id, new String[] { "req", "int" });
                if (!string.IsNullOrWhiteSpace(phone_number)) _val.val(phone_number, "int");
                if (email != null)
                {
                    _val.val(email, "email");
                }
                _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                int t_id = Convert.ToInt32(type_id);
                Byte type = (from t in this._db.recsys_type
                             where t.status == 1 && t.id == t_id
                             select t.type).FirstOrDefault();
                if (!String.IsNullOrWhiteSpace(username))
                {
                    if (_member.isExist(username, "username", oper != "edit" ? "" : "id != '" + id + "'"))
                    {
                        _val.setValStatus(false);
                    }
                }
                if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2))
                {
                    _val.val(password, "req");
                    _val.val(password2, new String[] { "req", "equal=" + password });
                }
                if (type == null || !this._ctr.Contains(center))
                {
                    _val.setValStatus(false);
                }
                if (this.isDuplicatePhoneNumber(phone_number, id, country_id))
                {
                    _val.setValStatus(false);
                }
                if(_val.getValStatus())
                {
                    grade = string.IsNullOrEmpty(grade) ? null : grade;
                    Hashtable data = new Hashtable() {
                        { "name", name },
                        { "type_id", type_id },
                        { "type", type },
                        { "user_group", user_group },
                        { "center", center },
                        { "username", username },
                        { "email", email },
                        { "status", status },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") },
                        { "employee_number", employee_number},
                        { "country_id", country_id },
                        { "phone_number", phone_number },
                        { "grade", grade }
                    };
                    if(! String.IsNullOrWhiteSpace(password)) {
                        data["password"] = password;
                    }
                    if(oper == "edit")
                    {
                        _member.update(data, id, "id");
                    }
                    else
                    {
                        _member.insert(data);
                        id = (from m in this._db.recsys_users
                              orderby m.id descending
                              select m.id).FirstOrDefault().ToString();
                    }
                }
                else
                {
                    return Content("false");
                }
            }
            else
            {
                this._db.ExecuteStoreCommand(Common.doDelete("relate", "id2 = '" + id + "' AND table1 = 'group' AND table2 = 'users'"));
                _member.delete(Convert.ToInt32(id));
                Common.delDir("Upload/users/" + id + "/");
            }
            return Content(id);
        }
 public ActionResult isExist()
 {
     string username = Common.doPost("username");
     string id = Common.doPost("id");
     Member _member = new Member("users");
     return Content(_member.isExist(username, "username", String.IsNullOrWhiteSpace(id) ? "" : "id != '" + id + "'") ? "false" : "true");
 }