public string Add(AddUserModel model)
        {
            if (ModelState.IsValid)
            {
                UserModel user = new UserModel();
                user.Code = model.Code;                             //登录名
                user.Password = "******".VariationMd5();            //默认密码

                user.Name = model.Name;                             //姓名
                user.Phone = model.Phone;                           //电话
                user.No = model.No;                                 //用户编号

                user.Departmentid = model.Departmentid.ToInt();     //部门
                user.Gender = model.Gender;                         //性别
                user.Age = model.Age;                               //年龄

                user.Status = model.Status;                         //用户状态
                user.Email = model.Email;                           //邮箱

                user.DelFlag = 0;                                   //有效状态
                user.CreateMan = SysConfig.CurrentUser.Id;          //创建人
                user.CreateTime = DateTime.Now;                     //创建时间
                int result = user.Insert().ToInt();

                if (result > 0)
                {
                    //记录操作日志
                    CommonMethod.Log(SysConfig.CurrentUser.Id, "Insert", "Sys_User");
                    return "1";
                }
            }
            return "0";
        }
 /// <summary>
 /// 检查登录名是否存在
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public JsonResult ValidateUserCode(AddUserModel model)
 {
     if (model != null && !string.IsNullOrWhiteSpace(model.Code))
     {
         //添加用户
         if (string.IsNullOrWhiteSpace(model.Id))
         {
             if (UserModel.Exists("Code = @0", model.Code))
             {
                 return Json("登录名已存在", JsonRequestBehavior.AllowGet);
             }
         }
         //编辑用户
         else
         {
             if (UserModel.Exists("Code = @0 and ID != @1", model.Code, model.Id))
             {
                 return Json("登录名已存在", JsonRequestBehavior.AllowGet);
             }
         }
     }
     return Json(true, JsonRequestBehavior.AllowGet);
 }
        public ActionResult Edit(string id)
        {
            #region 检查参数

            string currentPage = string.IsNullOrWhiteSpace(Request["CurrentPage"]) ? "1" : Request["CurrentPage"];
            string backUrl = "/Home/User/Index?backType=1&CurrentPage=" + currentPage;
            ViewBag.backUrl = backUrl;
            if (string.IsNullOrWhiteSpace(id))
            {
                return Redirect(backUrl);
            }

            #endregion

            #region 获取用户信息

            UserModel user = UserModel.SingleOrDefault(id);
            if (null == user)
            {
                return Redirect(backUrl);
            }

            AddUserModel model = new AddUserModel();
            model.Id = user.Id;
            model.Code = user.Code;
            model.Name = user.Name;
            model.Phone = user.Phone;
            model.No = user.No;
            model.Age = user.Age;
            model.Gender = user.Gender;
            model.Email = user.Email;
            model.Status = user.Status;
            model.Departmentid = user.Departmentid.ToString();

            string depIdList = "";
            ViewBag.depList = CommonMethod.GetFullDepartmentList(model.Departmentid.ToString(), out depIdList);
            ViewBag.depIdList = depIdList;

            return View(model);

            #endregion
        }
        public string Edit(AddUserModel model)
        {
            if (ModelState.IsValid)
            {
                UserModel user = UserModel.SingleOrDefault(model.Id);
                user.Code = model.Code;
                user.Name = model.Name;
                user.Age = model.Age;
                user.Gender = model.Gender;
                user.Phone = model.Phone;
                user.No = model.No;
                user.Departmentid = model.Departmentid.ToInt();
                user.Status = model.Status;
                user.Email = model.Email;
                user.ModifyMan = SysConfig.CurrentUser.Id;
                user.ModifyTime = DateTime.Now;

                int result = user.Update();

                if (result > 0)
                {
                    //记录操作日志
                    CommonMethod.Log(SysConfig.CurrentUser.Id, "Update", "Sys_User");

                    //更新缓存
                    SysConfig.CurrentUser = UserModel.SingleOrDefault(model.Id);

                    return "1";
                }
            }

            return "0";
        }
        public ActionResult Details(string id)
        {
            UserModel user = UserModel.SingleOrDefault(id);
            string currentPage = string.IsNullOrWhiteSpace(Request["CurrentPage"]) ? "1" : Request["CurrentPage"];
            string backUrl = "/Home/User/Index?backType=1&CurrentPage=" + currentPage;
            ViewBag.backUrl = backUrl;
            if (user == null)
            {
                return Redirect(backUrl);
            }

            AddUserModel model = new AddUserModel();
            model.Name = user.Name;
            model.Code = user.Code;
            model.Phone = user.Phone;
            model.No = user.No;
            model.Email = user.Email;
            model.Gender = user.Gender;
            model.Age = user.Age;
            model.Status = user.Status;

            DepartmentModel departmentModel = DepartmentModel.SingleOrDefault(user.Departmentid);
            ViewBag.department = departmentModel == null ? "" : departmentModel.FullName;

            return View(model);
        }