public async Task <User> SearchByIdAsync(int userId) { using (var db = LocalConnection.GetConnection()) { TB_USER user = await db.TB_USER.Where(u => u.ID == userId).FirstOrDefaultAsync(); return(new User() { UserId = user.ID, Email = user.EMAIL, Created_at = user.CREATE_DATE, FirstName = user.FIRIST_NAME, LastName = user.LAST_NAME }); } }
public static void LoadUser(TB_USER User) { General.Session[Static.Session.User] = User; HttpCookie ck = General.Request.Cookies[Static.Cookie.User]; if (ck == null) { ck = new HttpCookie(Static.Cookie.User, Crypto.EncryptStringAES(User.Id.ToString(), Static.Cookie.SharedSecret)); } if (ck.Expires < DateTime.Now) { ck.Value = Crypto.EncryptStringAES(User.Id.ToString(), Static.Cookie.SharedSecret); } ck.Expires = DateTime.Now.AddDays(1); General.Response.Cookies.Add(ck); SingleUser.AddUser(User.strAccountID, User.Id); }
public void Update(TB_USER m_TB_USER) { string sql = ""; sql = "update `TB_USER` set `REAL_NAME`={@REAL_NAME},`SEX`={@SEX},`ACCOUNT_STATUS`={@ACCOUNT_STATUS},`EMAIL`={@EMAIL},USER_IMAGE=@USER_IMAGE,USER_IMAGE_PATH={@USER_IMAGE_PATH},TITLE={@TITLE} where `USER_ID` = {@USER_ID} "; sql = sql.Replace("{@USER_ID}", Common.sqlNull(m_TB_USER.USER_ID)); sql = sql.Replace("{@REAL_NAME}", Common.sqlNull(m_TB_USER.REAL_NAME)); sql = sql.Replace("{@SEX}", Common.sqlNull(m_TB_USER.SEX)); sql = sql.Replace("{@ACCOUNT_STATUS}", Common.sqlNull(m_TB_USER.ACCOUNT_STATUS)); sql = sql.Replace("{@EMAIL}", Common.sqlNull(m_TB_USER.EMAIL)); sql = sql.Replace("{@TITLE}", Common.sqlNull(m_TB_USER.TITLE)); sql = sql.Replace("{@USER_IMAGE_PATH}", Common.sqlNull(m_TB_USER.USER_IMAGE_PATH)); using (var conn = Common.GetSqlConnection()) { var n = conn.Execute(sql, new TB_USER { USER_IMAGE = m_TB_USER.USER_IMAGE }); } }
public string CreateID() // Cơ chế sinh mã { string id = ""; Random rand = new Random(); for (int i = 0; i < 10; i++) { int a = rand.Next() % 10; a = a < 0 ? -1 * a : a; id += a.ToString(); } TB_USER user = Entities.TB_USER.Find(id); if (user != null) { return(CreateID()); } return(id); }
public ActionResult Create(TB_USER tb_user) { if (Session["USER"] == null) { return(RedirectToAction("../Account/ManagementLogin")); } if (ModelState.IsValid) { tb_user.LASTED_LOGIN = DateTime.Now; tb_user.CREATE_DATE = DateTime.Now; tb_user.CREATE_BY = 0; db.TB_USER.Add(tb_user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.STATUS = new SelectList(db.TB_M_STATUS.Where(s => s.STATUS_GROUP == 2), "STATUS_ID", "STATUS_NAME_TH", tb_user.STATUS); ViewBag.ROLE_ID = new SelectList(db.TB_ROLE, "ID", "NAME", tb_user.ROLE_ID); return(View(tb_user)); }
public ActionResult UserProfile() { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } if (string.IsNullOrEmpty(Session["last_user_id"].ToString())) { return(RedirectToAction("Index", "Login")); } String userid = (String)Session["last_user_id"]; IUSER bll = Bll_Utilitity.GetUser(); TB_USER user = bll.Get(userid); ViewData["user"] = user; List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); ViewData["sex"] = sex_list.AsEnumerable(); return(View()); }
public async Task <UserCredentials> SearchAsync(string login) { using (var db = LocalConnection.GetConnection()) { TB_USER user = await db.TB_USER.Where(u => u.EMAIL == login).FirstOrDefaultAsync(); if (user != null) { return(new UserCredentials() { Id = user.ID, IsActive = user.IS_ACTIVE, Email = user.EMAIL, Password = user.PASSWORD }); } else { return(null); } } }
// GET: Pay public ActionResult Payment() { //UserMessage MyUser = Session["UserMessage"] as UserMessage; MyUser = new UserMessage(); MyUser.id = 35; MyUser.name = "admin"; //string o_id = (Session["orderID"] as decimal?).ToString(); //Session.Remove("orderID"); string o_id = "24"; string SqlString = "SELECT P.PRICE,P.DISCOUNT_RATE FROM TB_PRODUCT P,TB_CONTAINS C,TB_ORDER O WHERE P.ID = C.P_ID AND P.S_ID = C.S_ID AND C.O_ID = O.ID AND O.ID =" + o_id; List <PriceRate> prices = db.Database.SqlQuery <PriceRate>(SqlString).ToList(); ViewModel.old_price = 0; ViewModel.new_price = 0; foreach (PriceRate item in prices) { ViewModel.old_price += item.price; ViewModel.new_price += item.price * item.rate; } Users user_db = new Users(); TB_USER user = user_db.TB_USER.Where(a => a.ID == MyUser.id).First(); if (user != null) { ViewModel.name = MyUser.name; ViewModel.phone = user.PHONE; ViewModel.province = user.PROVINCE; ViewModel.zipcode = user.ZIPCODE; ViewModel.city = user.CITY; ViewModel.creditcode = user.CREDIT_NO; ViewModel.district = user.DISTRICT; ViewModel.detailaddr = user.DETAILADDR; ViewModel.point_num = (decimal)ViewModel.old_price - decimal.Floor((decimal)ViewModel.old_price); ViewModel.check = true; } return(View(ViewModel)); }
public ActionResult getSignUp(TB_USER user) // đăng ký { var message = ""; try { if (ModelState.IsValid) { if (CheckUserName(user.USERNAME) != null) { message = "Tên đăng nhập đã được sử dụng !"; } else if (CheckEmail(user.EMAIL) != null) { message = "Email đã được sử dụng !"; } else { user.ID = CreateID(); Entities.TB_USER.Add(user); TB_MONEY money = new TB_MONEY(); money.USER_ACCOUNT_ID = user.ID; money.TOTAL_MONEY = 0; money.NEWBIE = 1; money.TIME_FOR_FREE = 3; Entities.TB_MONEY.Add(money); Entities.SaveChanges(); message = "Đăng ký thành công !"; } } } catch (Exception ex) { message = ex.GetBaseException().ToString(); } return(Json(message, JsonRequestBehavior.AllowGet)); }
public ActionResult Register(TB_USER model) { if (ModelState.IsValid) { using (var db = new Entities()) { var user = db.TB_USER.FirstOrDefault(u => u.LOGIN == model.LOGIN); if (user == null) { var crypt = new SimpleCrypto.PBKDF2(); var encrypts = crypt.Compute(model.PASSWD); var vUser = db.TB_USER.Create(); vUser.LOGIN = model.LOGIN; vUser.PASSWD = encrypts; vUser.PASSWSALT = crypt.Salt; vUser.USER_NAME = model.USER_NAME; db.TB_USER.Add(vUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", String.Format("Unable to create local account. An account with the name \"{0}\" may already exist.", model.LOGIN)); } } } else { ModelState.AddModelError("", "Dados incorretos"); } return(View());//model); }
public async Task <User> SearchByEmailAsync(string userEmail) { using (var db = LocalConnection.GetConnection()) { TB_USER user = await db.TB_USER.Where(u => u.EMAIL == userEmail).FirstOrDefaultAsync(); if (user != null) { return(new User() { UserId = user.ID, Email = user.EMAIL, Created_at = user.CREATE_DATE, FirstName = user.FIRIST_NAME, LastName = user.LAST_NAME }); } else { return(null); } } }
public ActionResult getLogin(TB_USER user) // đăng nhập { string message = ""; TB_USER users = Entities.TB_USER.Where(x => x.USERNAME == user.USERNAME.Trim() && x.PASSWORD_KEY.Trim() == user.PASSWORD_KEY).Select(x => x).SingleOrDefault(); if (users != null) { Session["UserID"] = users.ID; Session["UserName"] = VietHoa(users.NAME); message = "success"; } else { message = "empty"; } if (Request.IsAjaxRequest()) { return(Json(message, JsonRequestBehavior.AllowGet)); } else { return(RedirectToAction("Index", "Home")); } }
public TB_USER CheckUserName(string username) { TB_USER user = Entities.TB_USER.Where(x => x.USERNAME == username).SingleOrDefault(); return(user); }
public ActionResult ProfileSave() { IUSER bll = Bll_Utilitity.GetUser(); string user_id = (string)Session["last_user_id"]; TB_USER user = bll.Get(user_id); string real_name = Request["user.REAL_NAME"]; string sex = Request["sex"]; string old_password = Request["user.OLD_PASSWORD"]; string new_password = Request["user.NEW_PASSWORD"]; string re_password = Request["user.RE_PASSWORD"]; string email = Request["user.EMAIL"]; string image_file = Request["image_file"]; string title = Request["user.TITLE"]; user.USER_ID = user_id; user.REAL_NAME = real_name; user.SEX = sex; user.EMAIL = email; user.TITLE = title; string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads/" + image_file); bool change_password = false; if (System.IO.File.Exists(file_path)) { byte[] b = System.IO.File.ReadAllBytes(file_path); user.USER_IMAGE = b; user.USER_IMAGE_PATH = image_file; } bool isError = false; if (string.IsNullOrEmpty(user_id)) { ModelState.AddModelError("user.USER_ID", "用户ID不能为空"); isError = true; } if (string.IsNullOrEmpty(real_name)) { ModelState.AddModelError("user.REAL_NAME", "姓名不能为空"); isError = true; } if (new_password == "" && re_password == "") { } else if (new_password != re_password) { ModelState.AddModelError("user.RE_PASSWORD", "确认密码与输入密码不一致"); isError = true; } else { bool passowrd_collect = bll.isPasswordCorrect(user_id, old_password); if (!passowrd_collect) { ModelState.AddModelError("user.OLD_PASSWORD", "原密码错误"); isError = true; } else { user.PASSWORD = new_password; change_password = true; } } if (string.IsNullOrEmpty(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱不能为空"); isError = true; } if (!Validator.IsEmail(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱格式错误"); isError = true; } if (isError) { List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); ViewData["sex"] = sex_list.AsEnumerable(); return(View("UserProfile")); } bll.Update(user); if (change_password) { bll.SetPassword(user_id, new_password); } return(RedirectToAction("Index", "Board")); }
public ActionResult CreateSave() { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } string user_id0 = (string)Session["last_user_id"]; if (!p_helper.hasPermission("0110", user_id0)) { return(RedirectToAction("Index", "Login")); } IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IROLE p_bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list_role = p_bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); foreach (TB_ROLE bean in list_role) { checkState.Add(bean.ROLE_ID, false); } IUSER bll = Bll_Utilitity.GetUser(); string user_id = Request["user.USER_ID"]; string real_name = Request["user.REAL_NAME"]; string sex = Request["sex"]; string password = Request["user.PASSWORD"]; string re_password = Request["user.RE_PASSWORD"]; string email = Request["user.EMAIL"]; string account_status = Request["account_status"]; string image_file = Request["image_file"]; string title = Request["user.TITLE"]; TB_USER user = new TB_USER(); user.USER_ID = user_id; user.REAL_NAME = real_name; user.SEX = sex; user.PASSWORD = password; user.EMAIL = email; user.ACCOUNT_STATUS = account_status; user.TITLE = title; string roles = Request["role"]; string[] ps = null; if (!String.IsNullOrEmpty(roles)) { ps = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (ps != null && ps.Length > 0) { for (int ii = 0; ii < ps.Length; ii++) { if (checkState.ContainsKey(ps[ii])) { checkState[ps[ii]] = true; } } } } user.ROLE_LIST = list_role; string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads/" + image_file); if (System.IO.File.Exists(file_path)) { byte[] b = System.IO.File.ReadAllBytes(file_path); user.USER_IMAGE = b; user.USER_IMAGE_PATH = image_file; } bool isError = false; if (string.IsNullOrEmpty(user_id)) { ModelState.AddModelError("user.USER_ID", "用户ID不能为空"); isError = true; } if (string.IsNullOrEmpty(real_name)) { ModelState.AddModelError("user.REAL_NAME", "姓名不能为空"); isError = true; } if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("user.PASSWORD", "密码不能为空"); isError = true; } if (password != re_password) { ModelState.AddModelError("user.RE_PASSWORD", "确认密码与输入密码不一致"); isError = true; } if (string.IsNullOrEmpty(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱不能为空"); isError = true; } if (isError) { ViewData["user"] = user; ViewData["check_state"] = checkState; List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); return(View("Create")); } bll.Insert(user); bll.SetPassword(user.USER_ID, user.PASSWORD); string change_content = "用户ID:" + user.USER_ID + ",用户姓名:" + user.REAL_NAME; IOPLOG op_bll = Bll_Utilitity.GetOpLog(); TB_OP_LOG log = new TB_OP_LOG(); log.OP_USER_ID = (string)Session["last_user_id"]; log.OPER_NAME = "用户添加"; log.OPER_IP = IpHelper.GetClientIP(); log.OPER_TIME = DateTime.Now; log.OPER_DESC = "用户添加(" + change_content + ")"; op_bll.AddLog(log); IList <String> list = new List <String>(); if (ps != null) { foreach (string role_id in ps) { list.Add(role_id); } } rp_bll.Save(user.USER_ID, list); return(RedirectToAction("Index", "User")); }
public UserAndOrder() { User = new TB_USER(); Order = new List <OrderAndContains>(); }
public ActionResult Login(UserDTO UserLogin = null) { try { //remove validation because for login only need username and password ModelState.Remove("FULL_NAME"); ModelState.Remove("CONFIRM_PASSWORD"); ModelState.Remove("ROLE_ID"); ModelState.Remove("ROLE_NAME"); ModelState.Remove("USER_ID"); if (ModelState.IsValid) { if (UserLogin != null) { using (DBEntities db = new DBEntities()) { if (ModelState.IsValid) { //encrypt password with sha256 TB_USER user = db.TB_USER.FirstOrDefault(u => u.USERNAME == UserLogin.USERNAME); //if user is not already in database if (user == null) { TempData.Add("message", "User is not valid"); TempData.Add("type", "warning"); return(Redirect("~/auth/login")); } //if user is already in database else { string d = CryptographyUtils.Encrypt(UserLogin.PASSWORD); if (user.PASSWORD != CryptographyUtils.Encrypt(UserLogin.PASSWORD)) { TempData.Add("message", "Password Wrong"); TempData.Add("type", "warning"); return(Redirect("~/auth/login")); } else { //make session is filed by userDTO UserDTO userDTO = new UserDTO { ROLE_ID = user.ROLE_ID, USER_ID = user.USER_ID, USERNAME = user.USERNAME, EMAIL = user.EMAIL, FULL_NAME = user.FULL_NAME }; Session.Add("UserLogin", userDTO); return(Redirect("~/dashboard")); } } } } return(Redirect("~/auth/login")); } } return(Redirect("~/auth/login")); } catch (Exception) { return(Redirect("~/auth/error")); } }
public ActionResult Login() { ViewData["errMsg_user"] = ""; Session["login_in_success"] = ""; string userid = Request["userid"]; string password = Request["password"]; string remember_me = Request["hid_remember_me"]; if ("remember_me" == remember_me) { ViewData["remember_me_checked"] = "checked=\"checked\""; ViewData["remember_me"] = "remember_me"; } else { ViewData["remember_me_checked"] = ""; ViewData["remember_me"] = ""; } if (string.IsNullOrEmpty(userid)) { ViewData["errMsg_user"] = "******"; return(View("Index")); } if (string.IsNullOrEmpty(password)) { ViewData["errMsg_user"] = "******"; ViewData["last_user_id"] = userid; return(View("Index")); } IUSER bll = Bll_Utilitity.GetUser(); ILOGINLOG login_bll = Bll_Utilitity.GetLoginLog(); TB_USER user = bll.Get(userid); TB_LOGIN_LOG login_log = new TB_LOGIN_LOG(); login_log.LOG_USER_ID = userid; login_log.LOG_TIME = DateTime.Now; login_log.LOG_IP = IpHelper.GetClientIP(); if (user == null) { ViewData["errMsg_user"] = "******"; ViewData["last_user_id"] = userid; login_log.LOG_RESULT = "N"; login_bll.AddLog(login_log); return(View("Index")); } bool is_password_correct = bll.isPasswordCorrect(userid, password); if (!is_password_correct) { ViewData["errMsg_user"] = "******"; ViewData["last_user_id"] = userid; login_log.LOG_RESULT = "N"; login_bll.AddLog(login_log); return(View("Index")); } if ("remember_me" == remember_me) { HttpCookie mycookie = new HttpCookie("remember_me"); mycookie.Value = "remember_me"; mycookie.Path = "/"; mycookie.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(mycookie); HttpCookie mycookie2 = new HttpCookie("uid"); mycookie2.Value = userid; mycookie2.Path = "/"; mycookie2.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(mycookie2); } else { HttpCookie mycookie = new HttpCookie("remember_me"); mycookie.Value = ""; mycookie.Path = "/"; mycookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(mycookie); HttpCookie mycookie2 = new HttpCookie("uid"); mycookie2.Value = userid; mycookie2.Path = "/"; mycookie2.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(mycookie2); } PermissionHelper p_helper = new PermissionHelper(); Session["login_in_success"] = "true"; Session["last_user_id"] = userid; Session["real_name"] = user.REAL_NAME; Session["title"] = user.TITLE; Session["image_url"] = user.USER_IMAGE_PATH; Session[userid + "||permission_ids"] = p_helper.getAllPermissionIds(userid); login_log.LOG_RESULT = "Y"; login_bll.AddLog(login_log); return(RedirectToAction("Index", "Board")); }
public IEnumerable <TB_USER> GetList(int pageId, int pageSize, out int total) { total = 0; if (pageId <= 0) { pageId = 1; } if (pageSize <= 0) { pageSize = 10; } DataTable dt = new DataTable(); string sql = ""; string sqlWhere = " where 1=1 "; string sqlOrder = " order by USER_ID "; using ( SqlConnection conn = new SqlConnection(DbConfig.connStr)) { conn.Open(); sql = "select [USER_ID],[PASSWORD],[REAL_NAME],[SEX],[ACCOUNT_STATUS],[EMAIL],[USER_IMAGE_PATH],[TITLE] from [TB_USER]" + sqlWhere + sqlOrder; using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "p_splitpage"; SqlParameter pa_sql = new SqlParameter("@sql", sql); SqlParameter pa_page = new SqlParameter("@page", pageId); SqlParameter pa_pageSize = new SqlParameter("@pageSize", pageSize); SqlParameter pa_pageCount = new SqlParameter(); { pa_pageCount.ParameterName = "@pageCount"; pa_pageCount.Direction = ParameterDirection.InputOutput; pa_pageCount.DbType = DbType.Int32; pa_pageCount.Value = 0; } SqlParameter pa_recordCount = new SqlParameter(); { pa_recordCount.ParameterName = "@recordCount"; pa_recordCount.Direction = ParameterDirection.InputOutput; pa_recordCount.DbType = DbType.Int32; pa_recordCount.Value = 0; } SqlParameter pa_searchTime = new SqlParameter(); { pa_searchTime.ParameterName = "@SearchTime"; pa_searchTime.Direction = ParameterDirection.InputOutput; pa_searchTime.DbType = DbType.Int32; pa_searchTime.Value = 0; } cmd.Parameters.Add(pa_sql); cmd.Parameters.Add(pa_page); cmd.Parameters.Add(pa_pageSize); cmd.Parameters.Add(pa_pageCount); cmd.Parameters.Add(pa_recordCount); cmd.Parameters.Add(pa_searchTime); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds); dt = ds.Tables[1]; total = Convert.ToInt32(pa_recordCount.Value); } conn.Close(); } IList <TB_USER> list = new List <TB_USER>(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow row = dt.Rows[i]; TB_USER m = new TB_USER(); m.USER_ID = dt.Rows[i]["USER_ID"] as string; m.PASSWORD = ""; m.REAL_NAME = dt.Rows[i]["REAL_NAME"] as string; m.SEX = dt.Rows[i]["SEX"] as string; m.ACCOUNT_STATUS = dt.Rows[i]["ACCOUNT_STATUS"] as string; m.EMAIL = dt.Rows[i]["EMAIL"] as string; m.USER_IMAGE_PATH = dt.Rows[i]["USER_IMAGE_PATH"] as string; m.TITLE = dt.Rows[i]["TITLE"] as string; list.Add(m); } return(list as IEnumerable <TB_USER>); }
public ActionResult Edit(TB_USER user) { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } string user_id = (string)Session["last_user_id"]; if (!p_helper.hasPermission("0111", user_id)) { return(RedirectToAction("Index", "Login")); } if (user == null) { return(RedirectToAction("Index", "USER")); } if (string.IsNullOrEmpty(user.USER_ID)) { return(RedirectToAction("Index", "USER")); } IUSER r_bll = Bll_Utilitity.GetUser(); user = r_bll.Get(user.USER_ID); List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); IROLE bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list = bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IEnumerable <string> role_ids = rp_bll.GetRoleIds(user.USER_ID); user.ROLE_LIST = list; ViewData["user"] = user; IList <string> role_id_list = role_ids as IList <string>; foreach (TB_ROLE bean in list) { checkState.Add(bean.ROLE_ID, false); } foreach (string p_id in role_id_list) { if (checkState.ContainsKey(p_id)) { checkState[p_id] = true; } } ViewData["check_state"] = checkState; ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); if (user.USER_IMAGE != null && !string.IsNullOrEmpty(user.USER_IMAGE_PATH)) { string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, user.USER_IMAGE_PATH); if (!System.IO.File.Exists(file_path)) { System.IO.File.WriteAllBytes(file_path, user.USER_IMAGE); } } return(View()); }
public TB_USER CheckEmail(string email) { TB_USER user = Entities.TB_USER.Where(x => x.EMAIL == email).SingleOrDefault(); return(user); }
public ActionResult EditSave() { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } string user_id0 = (string)Session["last_user_id"]; if (!p_helper.hasPermission("0111", user_id0)) { return(RedirectToAction("Index", "Login")); } if (CommonConfig.isForDemo && user_id0.ToLower() == "admin") { TempData["ErrMsg"] = "演示版本,admin用户无法编辑"; return(RedirectToAction("Index", "USER")); } IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IROLE p_bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list_role = p_bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); foreach (TB_ROLE bean in list_role) { checkState.Add(bean.ROLE_ID, false); } IUSER bll = Bll_Utilitity.GetUser(); string user_id = Request["user.USER_ID"]; string real_name = Request["user.REAL_NAME"]; string sex = Request["sex"]; string old_password = Request["user.OLD_PASSWORD"]; string new_password = Request["user.NEW_PASSWORD"]; string re_password = Request["user.RE_PASSWORD"]; string email = Request["user.EMAIL"]; string account_status = Request["account_status"]; string image_file = Request["image_file"]; string title = Request["user.TITLE"]; TB_USER user = new TB_USER(); user.USER_ID = user_id; user.REAL_NAME = real_name; user.SEX = sex; user.EMAIL = email; user.ACCOUNT_STATUS = account_status; user.TITLE = title; string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads/" + image_file); if (System.IO.File.Exists(file_path)) { byte[] b = System.IO.File.ReadAllBytes(file_path); user.USER_IMAGE = b; user.USER_IMAGE_PATH = image_file; } string roles = Request["role"]; string[] ps = null; if (!String.IsNullOrEmpty(roles)) { ps = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (ps != null && ps.Length > 0) { for (int ii = 0; ii < ps.Length; ii++) { if (checkState.ContainsKey(ps[ii])) { checkState[ps[ii]] = true; } } } } user.ROLE_LIST = list_role; bool isError = false; bool change_password = false; if (string.IsNullOrEmpty(user_id)) { ModelState.AddModelError("user.USER_ID", "用户ID不能为空"); isError = true; } if (string.IsNullOrEmpty(real_name)) { ModelState.AddModelError("user.REAL_NAME", "姓名不能为空"); isError = true; } if (new_password == "" && re_password == "") { } else if (new_password != re_password) { ModelState.AddModelError("user.RE_PASSWORD", "确认密码与输入密码不一致"); isError = true; } else { bool passowrd_collect = bll.isPasswordCorrect(user_id, old_password); if (!passowrd_collect) { ModelState.AddModelError("user.OLD_PASSWORD", "原密码错误"); isError = true; } else { user.PASSWORD = new_password; change_password = true; } } if (string.IsNullOrEmpty(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱不能为空"); isError = true; } if (!Validator.IsEmail(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱格式错误"); isError = true; } if (isError) { ViewData["user"] = user; ViewData["check_state"] = checkState; List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); return(View("Edit")); } TB_USER old_user = bll.Get(user.USER_ID); bll.Update(user); if (change_password) { bll.SetPassword(user_id, new_password); } string change_content = ""; if (old_user.REAL_NAME != user.REAL_NAME) { change_content += string.Format("姓名({0}->{1})", old_user.REAL_NAME, user.REAL_NAME); } if (old_user.SEX != user.SEX) { if (change_content != "") { change_content += ","; } change_content += string.Format("性别({0}->{1})", old_user.SEX, user.SEX); } if (old_user.TITLE != user.TITLE) { if (change_content != "") { change_content += ","; } change_content += string.Format("称呼({0}->{1})", old_user.TITLE, user.TITLE); } if (old_user.USER_IMAGE_PATH != user.USER_IMAGE_PATH) { if (change_content != "") { change_content += ","; } change_content += string.Format("图片({0}->{1})", old_user.USER_IMAGE_PATH, user.USER_IMAGE_PATH); } IEnumerable <string> old_role_ids = rp_bll.GetRoleIds(user.USER_ID); IList <String> list = new List <String>(); if (ps != null) { foreach (string role_id in ps) { list.Add(role_id); } } rp_bll.Save(user.USER_ID, list); IList <string> old_role_id_list = old_role_ids.ToList <string>(); string result = CollectionUtilitity.compare("原包含角色", "现包含角色", old_role_id_list, list); if (result != "") { if (change_content != "") { change_content += ","; } change_content += result; } IOPLOG op_bll = Bll_Utilitity.GetOpLog(); TB_OP_LOG log = new TB_OP_LOG(); log.OP_USER_ID = (string)Session["last_user_id"]; log.OPER_NAME = "用户编辑"; log.OPER_IP = IpHelper.GetClientIP(); log.OPER_TIME = DateTime.Now; log.OPER_DESC = "用户编辑(" + change_content + ")"; op_bll.AddLog(log); return(RedirectToAction("Index", "User")); }
public void SaveDados(TB_USER objUser) { new USER_DAL().SaveUser(objUser); }
public ActionResult Payment(FormCollection collection) { if (collection["action"] == "cancel") { return(RedirectToAction("取消")); } PayViewModel ViewModel = new PayViewModel(); ViewModel.check = true; MyUser = new UserMessage(); MyUser.id = 35; MyUser.name = "admin"; string NewPassword = Request.Form["password"]; string NewDetailAddr = Request.Form["detailaddr"]; string NewCity = Request.Form["city"]; string NewProvince = Request.Form["province"]; int result; int NewZipCode, NewCardNum; if (int.TryParse(Request.Form["zipcode"], out result)) { NewZipCode = result; } else { NewZipCode = 0; } int result2; if (int.TryParse(Request.Form["creditcode"], out result2)) { NewCardNum = result2; } else { NewCardNum = 0; } string NewDistrict = Request.Form["district"]; old_user = db2.TB_USER.Where(a => a.ID == MyUser.id).FirstOrDefault(); if (NewPassword != "" && NewPassword != old_user.PASSWORD) { old_user.PASSWORD = NewPassword; } if (NewCardNum != 0 && NewCardNum != old_user.CREDIT_NO) { old_user.CREDIT_NO = NewCardNum; } if (NewDetailAddr != "" && NewDetailAddr != old_user.DETAILADDR) { old_user.DETAILADDR = NewDetailAddr; } if (NewCity != "" && NewCity != old_user.CITY) { old_user.CITY = NewCity; } if (NewProvince != "" && NewProvince != old_user.PROVINCE) { old_user.PROVINCE = NewProvince; } if (NewZipCode != 0 && NewZipCode != old_user.ZIPCODE) { old_user.ZIPCODE = NewZipCode; } if (NewDistrict != "" && NewDistrict != old_user.DISTRICT) { old_user.DISTRICT = NewDistrict; } if (NewPassword != old_user.PASSWORD) { } db.SaveChanges(); if (NewPassword != old_user.PASSWORD) { ViewModel.check = false; return(View(ViewModel)); } return(RedirectToAction("完成成功")); }
private List <string> UserEquals(TB_USER beforeuser, TB_USER user, string rids, string rnames) { string str = string.Empty; string str2 = string.Empty; // logcontent = "新增用户|登录账号:" + user.LOGINNAME + ";真实姓名:" + user.REALNAME + ";性别:" + user.SEX + ";手机:" + user.TEL + ";所属单位:" + user.UNIT + ";邮箱:" + user.EMAIL + ";密码:" + pwd + ";拥有角色:" + rnames + ""; //遍历实体类属性改null为empty PropertyInfo[] propertys = beforeuser.GetType().GetProperties() as PropertyInfo[]; foreach (PropertyInfo property in propertys) { if (property.GetValue(beforeuser, null) == null) { if (property.PropertyType.Name == typeof(String).Name) { property.SetValue(beforeuser, string.Empty, null); } } } if (!user.REALNAME.Trim().Equals(beforeuser.REALNAME.Trim()) && user.REALNAME != null) { str += "真实姓名从'" + beforeuser.REALNAME + "'修改为'" + user.REALNAME + "';"; str2 += "REALNAME:" + user.REALNAME + ";"; } if (!user.SEX.Trim().Equals(beforeuser.SEX.Trim())) { str += "性别从'" + beforeuser.SEX + "'修改为'" + user.SEX + "';"; str2 += "SEX:" + user.SEX + ";"; } if (!user.TEL.Trim().Equals(beforeuser.TEL.Trim())) { str += "联系电话从'" + beforeuser.TEL + "'修改为'" + user.TEL + "';"; str2 += "TEL:" + user.TEL + ";"; } if (!user.UNIT.Trim().Equals(beforeuser.UNIT.Trim())) { str += "所属单位从'" + beforeuser.UNIT + "'修改为'" + user.UNIT + "';"; str2 += "UNIT:" + user.UNIT + ";"; } if (!user.EMAIL.Trim().Equals(beforeuser.EMAIL.Trim())) { str += "邮箱从'" + beforeuser.EMAIL + "'修改为'" + user.EMAIL + "';"; str2 += "EMAIL:" + user.EMAIL + ";"; } if (!user.MEMO.Trim().Equals(beforeuser.MEMO.Trim())) { str += "备注从'" + beforeuser.MEMO + "'修改为'" + user.MEMO + "';"; str2 += "MEMO:" + user.MEMO + ";"; } if (!user.PWD.Trim().Equals(beforeuser.PWD.Trim())) { str += "密码从'" + DESEncrypt.Decrypt(beforeuser.PWD) + "'修改为'" + DESEncrypt.Decrypt(user.PWD) + "';"; str2 += "PWD:" + DESEncrypt.Decrypt(user.PWD) + ";"; } DataSet ds_role = userbll.sel(int.Parse(beforeuser.USERID.ToString())); string before_role = string.Empty; if (ds_role != null) { for (int i = 0; i < ds_role.Tables[0].Rows.Count; i++) { before_role += ds_role.Tables[0].Rows[i]["rname"].ToString() + ","; } } if (!string.IsNullOrEmpty(before_role) && !string.IsNullOrEmpty(rnames)) { before_role = before_role.Substring(0, before_role.Length - 1); rnames = rnames.Substring(0, rnames.Length - 1); string[] arr1 = before_role.Split(','); string[] arr2 = rnames.Split(','); bool change = false; if (arr1.Length != arr2.Length) { change = true; } else { for (int i = 0; i < arr2.Length; i++) { bool temp = false; for (int j = 0; j < arr1.Length; j++) { if (arr2[i].Trim().Equals(arr1[j].Trim())) { temp = true; continue; } if (j == arr1.Length - 1 && !temp) { change = true; } } } } if (change) { str += "拥有角色从'" + before_role + "'修改为'" + rnames + "';"; str2 += "rids:" + rnames + ";"; } } List <string> list = new List <string>(); list.Add(str); list.Add(str2); return(list); }
public string AddAUserSave(int id, string loginname, string username, string tel, string unitid, string unit, string duty, string email, string password, string sex, string rid, string rname, string memo, string reason) { MessageModel <string> result = new MessageModel <string>(); TB_USER user = null; string r = string.Empty; if (id == -1) { if (userbll.Exists(loginname)) { result.data = null; result.code = System.Net.HttpStatusCode.BadRequest; result.success = false; result.msg = "已经存在相同名称的用户"; r = Newtonsoft.Json.JsonConvert.SerializeObject(result); return(r); } user = new TB_USER(); } else { user = userbll.GetModel(id); } user.LOGINNAME = loginname; user.REALNAME = username; user.SEX = sex == null ? "" : sex; user.TEL = tel == null ? "" : tel; user.UNITID = int.Parse(unitid); user.UNIT = unit == null ? "" : unit; user.DUTY = duty == null ? "" : duty; user.EMAIL = email == null ? "" : email; user.MEMO = memo == null ? "" : memo; user.PWD = DESEncrypt.Encrypt(password); if (id == -1) { user.ISSYSADMIN = "0"; user.ADDTIME = DateTime.Now; user.CREATEUID = int.Parse(usermodel.USERID.ToString()); int tmp = userbll.USERAdd(user); if (tmp > 0) { TB_USER_ROLE bll = new TB_USER_ROLE(); user_role.Delete(tmp); TB_ROLE_LOG rlog = new TB_ROLE_LOG(); TB_ROLE_LOG_PROCESS rlog_p = new TB_ROLE_LOG_PROCESS(); rlog.OID = tmp; rlog.TYPE = "TB_USER"; rlog.STATUS = "0"; rlog.BEFORE_CONTENT = string.Empty; rlog.REMARK = reason; string logcontent = string.Empty; string sqlremark = string.Empty; logcontent = "新增用户|登录账号:" + user.LOGINNAME + ";真实姓名:" + user.REALNAME + ";性别:" + user.SEX + ";联系电话:" + user.TEL + ";所属单位:" + user.UNIT + ";邮箱:" + user.EMAIL + ";密码:" + password + ";拥有角色:" + rname + ""; sqlremark = "LOGINNAME:" + user.LOGINNAME + ";REALNAME:" + user.REALNAME + ";SEX:" + user.SEX + ";TEL:" + user.TEL + ";UNIT:" + user.UNIT + ";EMAIL:" + user.EMAIL + ";pwd:" + password + ";rids:" + rid + ""; rlog.CONTENT = logcontent; rlog.SQLREMARK = sqlremark;; string logsql = string.Empty; if (rid != "") { string[] rids = rid.Split(','); for (int i = 0; i < rids.Length; i++) { if (rids[i] != "" && Convert.ToInt32(rids[i]) > 0) { logsql += "insert into TB_USER_ROLE(USERID,ROLEID) values('" + tmp + "','" + rids[i] + "');"; } } } logsql = !string.IsNullOrEmpty(logsql) ? logsql.Substring(0, logsql.Length - 1) : string.Empty; rlog.SAVESQL = logsql; int logid = userbll.AddROLE_LOG(rlog); string msg = string.Empty; if (logid != -1) { rlog_p.LID = logid; rlog_p.OMAN = usermodel.REALNAME; rlog_p.OTIME = DateTime.Now; rlog_p.REMARK = "待审批"; userbll.AddROLE_LOG_PROCESS(rlog_p); msg = "新增成功!等待审批后生效!"; } else { msg = "新增失败!"; } result.data = null; result.code = System.Net.HttpStatusCode.OK; result.success = false; result.msg = msg; r = Newtonsoft.Json.JsonConvert.SerializeObject(result); } } else { TB_USER users = userbll.GetModel(id); List <string> list = UserEquals(users, user, rid, rname); string logcontent = list[0]; string sqlremark = list[1]; string msg = string.Empty; if (!string.IsNullOrEmpty(logcontent)) { TB_ROLE_LOG rlog = new TB_ROLE_LOG(); TB_ROLE_LOG_PROCESS rlog_p = new TB_ROLE_LOG_PROCESS(); rlog.OID = id; rlog.TYPE = "TB_USER"; rlog.STATUS = "0"; rlog.BEFORE_CONTENT = string.Empty; rlog.REMARK = reason; logcontent = "编辑用户|" + logcontent; rlog.CONTENT = logcontent; rlog.SQLREMARK = sqlremark; string logsql = "update TB_USER set LOGINNAME='" + user.LOGINNAME + "',PWD='" + user.PWD + "',REALNAME='" + user.REALNAME + "',SEX='" + user.SEX + "',TEL='" + user.TEL + "',UNIT='" + user.UNIT + "',DUTY='" + user.DUTY + "',EMAIL='" + user.EMAIL + "',UNITID='" + user.UNITID + "',memo='" + user.MEMO + "' where USERID=" + id + ";"; logsql += "delete from TB_USER_ROLE where userid=" + id + ";"; if (rid != "" && rid != null) { string[] rids = rid.Split(','); for (int i = 0; i < rids.Length; i++) { if (rids[i] != "" && Convert.ToInt32(rids[i]) > 0) { logsql += "insert into TB_USER_ROLE(USERID,ROLEID) values('" + id + "','" + rids[i] + "');"; } } } logsql = !string.IsNullOrEmpty(logsql) ? logsql.Substring(0, logsql.Length - 1) : string.Empty; rlog.SAVESQL = logsql; int logid = userbll.AddROLE_LOG(rlog); if (logid != -1) { rlog_p.LID = logid; rlog_p.OMAN = usermodel.REALNAME; rlog_p.OTIME = DateTime.Now; rlog_p.REMARK = "待审批"; userbll.AddROLE_LOG_PROCESS(rlog_p); msg = "编辑成功!等待审批后生效!"; } else { msg = "编辑失败!"; } } else { msg = "编辑成功!"; } result.data = null; result.code = System.Net.HttpStatusCode.OK; result.success = false; result.msg = msg; r = Newtonsoft.Json.JsonConvert.SerializeObject(result); } return(r); }
public ActionResult Register(TB_USER User, string repassword, string agree) { #region Required fills if (User.strAccountID == null) { TempData["Error"] = "Error : AccountID can not be null."; return(View(User)); } if (User.strPasswd == null) { TempData["Error"] = "Error : Password can not be null."; return(View(User)); } if (User.strPasswd != repassword) { TempData["Error"] = "Error : Passwords does not match."; return(View(User)); } if (repassword == null) { TempData["Error"] = "Error : Password confirm can not be null."; return(View(User)); } if (User.strEmail == null) { TempData["Error"] = "Error : Email address can not be null."; return(View(User)); } if (User.sQuestionId == 0) { TempData["Error"] = "Error : Please select Secret Question."; return(View(User)); } if (User.sQuestionAnswer == null) { TempData["Error"] = "Error : Please enter secret question answer."; return(View(User)); } if (agree != "Y") { TempData["Error"] = "Error : You must read and agree our Terms of Service."; return(View(User)); } if (!Functions.ValidAccountID(User.strAccountID)) { TempData["Error"] = "Please enter a valid Account ID."; return(View(User)); } if (!Functions.ValidAccountID(User.strPasswd)) { TempData["Error"] = "Please enter a valid Password."; return(View(User)); } if (!Functions.ValidEmail(User.strEmail)) { TempData["Error"] = "Please enter a valid email address."; return(View(User)); } #endregion TB_USER accid = AccountDB.TB_USER.FirstOrDefault(d => d.strAccountID == User.strAccountID); if (accid != null) { TempData["Error"] = "Error : This Account ID already in use."; return(View(User)); } TB_USER email = AccountDB.TB_USER.FirstOrDefault(d => d.strEmail == User.strEmail); if (email != null) { TempData["Error"] = "Error : This Email already in use."; return(View(User)); } TB_USER dbUser = new TB_USER(); dbUser.strAccountID = User.strAccountID; dbUser.strPasswd = User.strPasswd; dbUser.strSocNo = "1"; dbUser.strEmail = User.strEmail; dbUser.strAuthority = 1; dbUser.sQuestionId = User.sQuestionId; dbUser.sQuestionAnswer = User.sQuestionAnswer; dbUser.PremiumExpire = DateTime.Now.AddDays(3); dbUser.CountryId = User.CountryId; AccountDB.TB_USER.Add(dbUser); try { TempData["Information"] = "Your account has been created!"; AccountDB.SaveChanges(); } catch (Exception) { throw; } return(View()); }
public ActionResult Update(string NewPassword, int?NewCardNum, string NewDetailAddr, string NewCity, string NewProvince, int?NewZipCode, string NewDistrict, int?NewPhone) { //userMes = Session["UserMessage"] as UserMessage; userMes = new UserMessage(); //userMes.id = 24; //userMes.name = "liuzhili"; userMes = Session["UserMessage"] as UserMessage; NewPassword = Request.Form["first_password"]; NewDetailAddr = Request.Form["detail_address"]; NewCity = Request.Form["city"]; NewProvince = Request.Form["province"]; int result; if (int.TryParse(Request.Form["zipcode"], out result)) { NewZipCode = result; } else { NewZipCode = 0; } int result2; if (int.TryParse(Request.Form["credit_no"], out result2)) { NewCardNum = result2; } else { NewCardNum = 0; } int result3; if (int.TryParse(Request.Form["phone"], out result3)) { NewPhone = result3; } else { NewPhone = 0; } NewDistrict = Request.Form["district"]; //string SqlString = "select * from TB_USER where ID = " + userMes.id.ToString(); //TB_USER old_user = db.Database.SqlQuery<TB_USER>(SqlString).First(); old_user = db.TB_USER.Where(a => a.ID == userMes.id).FirstOrDefault(); if (Request.Form["first_password"] != Request.Form["second_password"]) { ViewData["check_password"] = false; return(View(old_user)); } ViewData["check_password"] = true; if (NewPassword != "" && NewPassword != old_user.PASSWORD) { old_user.PASSWORD = NewPassword; } if (NewCardNum != 0 && NewCardNum != old_user.CREDIT_NO) { old_user.CREDIT_NO = NewCardNum; } if (NewDetailAddr != "" && NewDetailAddr != old_user.DETAILADDR) { old_user.DETAILADDR = NewDetailAddr; } if (NewCity != "" && NewCity != old_user.CITY) { old_user.CITY = NewCity; } if (NewProvince != "" && NewProvince != old_user.PROVINCE) { old_user.PROVINCE = NewProvince; } if (NewZipCode != 0 && NewZipCode != old_user.ZIPCODE) { old_user.ZIPCODE = NewZipCode; } if (NewDistrict != "" && NewDistrict != old_user.DISTRICT) { old_user.DISTRICT = NewDistrict; } if (NewPhone != 0 && NewPhone != old_user.PHONE) { old_user.PHONE = NewPhone; } db.SaveChanges(); return(View(old_user)); }
public void UpdateUser(TB_USER objUser) { new USER_DAL().UpdateUser(objUser); }
public ActionResult Details(TB_USER user) { if (user == null) { return(RedirectToAction("Index", "USER")); } if (string.IsNullOrEmpty(user.USER_ID)) { return(RedirectToAction("Index", "USER")); } IUSER r_bll = Bll_Utilitity.GetUser(); user = r_bll.Get(user.USER_ID); List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); IROLE bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list = bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IEnumerable <string> role_ids = rp_bll.GetRoleIds(user.USER_ID); user.ROLE_LIST = list; ViewData["user"] = user; IList <string> role_id_list = role_ids as IList <string>; foreach (TB_ROLE bean in list) { checkState.Add(bean.ROLE_ID, false); } foreach (string p_id in role_id_list) { if (checkState.ContainsKey(p_id)) { checkState[p_id] = true; } } ViewData["check_state"] = checkState; ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); return(View()); }