public ActionResult Change(RegisterDto UserInfo)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    //如果ModelState.IsValid == false就表示UserInfo这个实体类对象中贴了特性标签的所有属性中至少有一个属性验证不通过(它会遍历UserInfo这个类对象的所有属性,检查属性上面的特性标签,然后判断用户输入的数据是否符合特性标签的约束条件,如果不符合就返回了fase)

                    //加入程序员自定义的提示信息
                    ModelState.AddModelError("", "实体验证不合法");

                    //List<RoomDto> list = new List<RoomDto>();
                    //list = roomService.GetAll();
                    //SelectList selList = new SelectList(list, "ID", "Name", UserInfo.Room_Name);
                    //ViewData["Users"] = selList;
                    return(View(UserInfo)); //数据验证不通过后,重新跳到新增页面。
                }

                bool Update = UserManService.UpdateRole(UserInfo);
                if (Update)
                {
                    //return Content("<script>alert('修改成功!');window.location.href='UserManage';</script>");
                    ViewBag.ChaMessage = "修改成功!";
                }
                else
                {
                    //return Content("<script>alert('修改失败!');window.location.href='Change';</script>");
                    ViewBag.ChaMessage = "修改失败!";
                }
            }
            catch
            {
            }
            return(RedirectPermanent("/UserManage/Change?name=" + UserInfo.Name + "&flag=true"));
        }
 public JsonResult getUserManage(string userName, int pageSize, int curPage, string userRole, bool selectIsTea, int roomID) //获取用户,登陆的如果是教师只能获取学生,如果是管理员则可以获取教师和学生
 {
     try
     {
         long recordCount            = 0;
         List <UserManDto> adminList = new List <UserManDto>();
         adminList = UserManService.getUserManage(userName, pageSize, curPage, userRole, selectIsTea, roomID, out recordCount);
         string adminJson = JsonConvert.SerializeObject(new { recordCount = recordCount, adminList = adminList });
         return(Json(adminJson));
     }
     catch { return(null); }
 }
 public ContentResult UserDel(int userId) //用户删除,当学生或教师离开实验室,可以将其有关信息删除
 {
     try
     {
         bool success = UserManService.UserDel(userId);
         if (success)
         {
             return(Content("true"));
         }
         else
         {
             return(Content("false"));
         }
     }
     catch { return(Content("false")); }
 }
        public ContentResult UserCheck(int userId, string email) //用户审核,用于审核刚注册的用户
        {
            try
            {
                bool success = UserManService.UserCheck(userId);
                if (success)
                {
                    string senderServerIp  = ConfigHelp.GetConfigValue("smtptype");    //使用163代理邮箱服务器(也可是使用qq的代理邮箱服务器,但需要与具体邮箱对相应)
                    string toMailAddress   = email;                                    //要发送对象的邮箱
                    string fromMailAddress = ConfigHelp.GetConfigValue("useraddress"); //你的邮箱
                    string subjectInfo     = "审核通过消息";                                 //主题
                    string bodyInfo        = "<p>" + "注册已通过审核,请前往“登陆”页面进行登陆" + "</p>"; //以Html格式发送的邮件
                    string mailUsername    = ConfigHelp.GetConfigValue("user");        //登录邮箱的用户名
                    string mailPassword    = ConfigHelp.GetConfigValue("pass");        //对应的登录邮箱的第三方密码(你的邮箱不论是163还是qq邮箱,都需要自行开通stmp服务)
                    string mailPort        = "25";                                     //发送邮箱的端口号
                    //string attachPath = "E:\\123123.txt; E:\\haha.pdf";

                    //创建发送邮箱的对象
                    Email myEmail = new Email(senderServerIp, toMailAddress, fromMailAddress, subjectInfo, bodyInfo, mailUsername, mailPassword, mailPort, true, false);

                    if (myEmail.Send())
                    {
                        return(Content("true"));
                    }
                    else
                    {
                        return(Content("false"));
                    }
                }
                else
                {
                    return(Content("false"));
                }
            }
            catch { return(Content("false")); }
        }