public bool IsValidUser(UserInfor u) { if (u.UserName == "419" && u.Pwd == "419") { return true; } else { return false; } }
public ActionResult UserInfor(string lan, int? id) { lan = this.Internationalization(); TugDataEntities db = new TugDataEntities(); System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp = u => u.UserName == User.Identity.Name; UserInfor user = db.UserInfor.Where(exp).FirstOrDefault(); UserInfor curUser = new UserInfor(); curUser.UserName = user.UserName; curUser.Name1 = user.Name1; curUser.Name2 = user.Name2; curUser.Dept = user.Dept; curUser.Sec = user.Sec; curUser.Sex = user.Sex; curUser.WorkNumber = user.WorkNumber; curUser.Tel = user.Tel; curUser.Email = user.Email; return View(curUser); }
public ActionResult SavePwd() { string pwd = Request.Form["Pwd"].ToString(); string newpwd = Request.Form["newPwd"].ToString(); TugDataEntities db = new TugDataEntities(); UserInfor newUser = new UserInfor(); System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp = u => u.UserName == User.Identity.Name && u.Pwd == pwd; UserInfor user = db.UserInfor.Where(exp).FirstOrDefault(); if (user != null) //原密码验证通过 { user.Pwd = newpwd; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return Json(new { message = "新密码已生效,请重新登录!" }); } else //原密码错误 { //Response.StatusCode = (int)HttpStatusCode.BadRequest; Response.StatusCode = 404; return Json(new { message = "原密码不正确,请重新输入!" }); } }
public ActionResult SaveNewUser() { string tmpUser = Request.Form["UserName"].ToString(); string name1 = Request.Form["Name1"].ToString(); TugDataEntities db = new TugDataEntities(); try { UserInfor newUser = new UserInfor(); System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp = u => u.UserName == tmpUser; UserInfor user = db.UserInfor.Where(exp).FirstOrDefault(); if (user != null) //用户名已被占用 { //Response.StatusCode = 404; //return Json(new { code = Resources.Common.Information_CODE, message = Resources.Common.Information_MESSAGE }); throw new Exception("用户名已存在!"); } System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp1 = u => u.Name1 == name1; UserInfor user1 = db.UserInfor.Where(exp1).FirstOrDefault(); if (user1 != null) //用户名已被占用 { //Response.StatusCode = 404; //return Json(new { code = Resources.Common.Information_CODE, message = Resources.Common.Information_MESSAGE }); throw new Exception("中文名已存在!"); } newUser.Name1 = Request.Form["Name1"].ToString(); newUser.UserName = Request.Form["UserName"].ToString(); newUser.Email = Request.Form["Email"].ToString(); newUser.Pwd = Request.Form["Pwd"].ToString(); newUser.IsGuest = "true"; newUser = db.UserInfor.Add(newUser); db.SaveChanges(); FormsAuthentication.SetAuthCookie(tmpUser, false); return Json(new { message = "注册成功!" }); } catch (Exception ex) { throw ex; } }
public ActionResult UserAddEdit() { this.Internationalization(); var treeidx = Request["treeid"]; if (treeidx == "") { } else { } #region Add if (Request.Form["oper"].Equals("add")) { try { TugDataEntities db = new TugDataEntities(); { TugDataModel.UserInfor usobj = new UserInfor(); usobj.UserName = Request.Form["UserName"]; usobj.Pwd = Request.Form["Pwd"]; usobj.IsGuest = Request.Form["IsGuest"]; usobj.LanUserName = Request.Form["LanUserName"]; usobj.Lan = Request.Form["Lan"]; usobj.Dept = Request.Form["Dept"]; usobj.Sec = Request.Form["Sec"]; usobj.Name1 = Request.Form["Name1"]; usobj.Name2 = Request.Form["Name2"]; usobj.WorkNumber = Request.Form["WorkNumber"]; usobj.Sex = Request.Form["Sex"]; usobj.Tel = Request.Form["Tel"]; usobj.Email = Request.Form["Email"]; usobj.OwnerID = -1; usobj.CreateDate = usobj.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");; usobj.AddUserID = Session.GetDataFromSession<int>("userid"); usobj.System = Request.Form["System"]; usobj.Status = -1; usobj.LogIP = Request.Form["LogIP"]; usobj.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; usobj.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; usobj.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; usobj.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") usobj.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") usobj.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") usobj.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") usobj.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); usobj.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; usobj.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; usobj = db.UserInfor.Add(usobj); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception) { var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //Response.Write(@Resources.Common.EXCEPTION_MESSAGE); return Json(ret); } } #endregion Add #region Edit if (Request.Form["oper"].Equals("edit")) { try { TugDataEntities db = new TugDataEntities(); int idx = Util.toint(Request.Form["IDX"]); string username = Request.Form["UserName"]; System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp = u => u.UserName == username && u.IDX != idx; UserInfor tmpUserName = db.UserInfor.Where(exp).FirstOrDefault(); if (tmpUserName != null) { return Json(new { code = Resources.Common.ERROR_CODE, message = "用户名已存在!" });//Resources.Common.ERROR_MESSAGE } string name1 = Request.Form["Name1"]; System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp1 = u => u.UserName == username && u.IDX != idx; UserInfor us = db.UserInfor.Where(exp1).FirstOrDefault(); if (us != null) { return Json(new { code = Resources.Common.ERROR_CODE, message = "姓名1已存在!" });//Resources.Common.ERROR_MESSAGE } UserInfor usobj = db.UserInfor.Where(u => u.IDX == idx).FirstOrDefault(); if (usobj == null) { return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); } else { usobj.UserName = Request.Form["UserName"]; usobj.Pwd = Request.Form["Pwd"]; usobj.IsGuest = Request.Form["IsGuest"]; usobj.LanUserName = Request.Form["LanUserName"]; usobj.Lan = Request.Form["Lan"]; usobj.Dept = Request.Form["Dept"]; usobj.Sec = Request.Form["Sec"]; usobj.Name1 = Request.Form["Name1"]; usobj.Name2 = Request.Form["Name2"]; usobj.WorkNumber = Request.Form["WorkNumber"]; usobj.Sex = Request.Form["Sex"]; usobj.Tel = Request.Form["Tel"]; usobj.Email = Request.Form["Email"]; usobj.OwnerID = -1; usobj.CreateDate = usobj.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");; usobj.AddUserID = Session.GetDataFromSession<int>("userid"); usobj.System = Request.Form["System"]; usobj.Status = -1; usobj.LogIP = Request.Form["LogIP"]; usobj.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; usobj.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; usobj.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; usobj.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") usobj.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") usobj.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") usobj.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") usobj.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); usobj.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; usobj.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; db.Entry(usobj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); } } catch (Exception exp) { return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }); } } #endregion Edit return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); }
public ActionResult AddUser(string UserName,string Dept,string Sec,string Name1,string Name2,string WorkNumber,string Sex,string Tel,string Email) { this.Internationalization(); try { TugDataEntities db = new TugDataEntities(); { System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp = u => u.UserName == UserName; UserInfor tmpUserName = db.UserInfor.Where(exp).FirstOrDefault(); if (tmpUserName != null) { //Response.StatusCode = 404; //return Json(new { message = "用户名已存在!" }); throw new Exception("用户名已存在!"); } System.Linq.Expressions.Expression<Func<UserInfor, bool>> exp1 = u => u.Name1 == Name1; UserInfor tmpName1 = db.UserInfor.Where(exp).FirstOrDefault(); if (tmpName1 != null) { //Response.StatusCode = 404; //var ret = new { message = "中文名已存在!" }; //return Json(ret); throw new Exception("姓名1已存在!"); } TugDataModel.UserInfor usobj = new UserInfor(); usobj.UserName =UserName; usobj.Pwd = "123"; usobj.IsGuest = "false"; usobj.LanUserName ="" ; usobj.Lan =""; usobj.Dept =Dept; usobj.Sec =Sec ; usobj.Name1 =Name1 ; usobj.Name2 = Name2; usobj.WorkNumber =WorkNumber ; usobj.Sex =Sex ; usobj.Tel =Tel ; usobj.Email = Email; usobj.OwnerID = -1; usobj.CreateDate = usobj.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; usobj.AddUserID = Session.GetDataFromSession<int>("userid"); usobj.System = "Tug"; usobj.Status = -1; usobj.LogIP = ""; usobj.UserDefinedCol1 = ""; usobj.UserDefinedCol2 = ""; usobj.UserDefinedCol3 = ""; usobj.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"] != "") // usobj.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); //if (Request.Form["UserDefinedCol6"] != "") // usobj.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); //if (Request.Form["UserDefinedCol7"] != "") // usobj.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); //if (Request.Form["UserDefinedCol8"] != "") // usobj.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); usobj.UserDefinedCol9 = ""; usobj.UserDefinedCol10 = ""; usobj = db.UserInfor.Add(usobj); db.SaveChanges(); var ret1 = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret1); } } catch (Exception ex) { throw ex; } }