public ActionResult Register(TS_USERDTO userDto) { #region #endregion //DTO转换EF实体 TS_USER user = AutoMapper.Mapper.Map <TS_USER>(userDto); //验证实体字段 if (!ModelState.IsValid) { return(View()); } //验证登录名是否重复 if (service.GetUser(user.C_ACCOUNT) == null) { user.C_ID = Guid.NewGuid().ToString(); user.N_STATUS = 2; user.N_TYPE = 1; user.D_LASTLOGINTIME = DateTime.Now; user.D_MOD_DT = DateTime.Now; user.C_PASSWORD = Encrypt.MD5(user.C_PASSWORD); service.UserRegister(user); return(Content("<script>alert('注册成功!');window.location.href='../Auth/Login';</script>")); } //登录名重复 else { ModelState.AddModelError("C_ACCOUNT", "登录名重复"); } return(View(userDto)); }
/// <summary> /// 用ID获取登录名 /// </summary> /// <param name="id"></param> /// <returns></returns> public TS_USERDTO Get(string id) { TS_USER user = _UserMenu.FirstOrDefault(u => u.C_ID.Equals(id)); TS_USERDTO dto = AutoMapper.Mapper.Map <TS_USERDTO>(user); List <TS_USER_DEPT> list = _UserDept.Where(x => x.C_USER_ID.Equals(user.C_ACCOUNT)).ToList(); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { string deptid = list[i].C_DEPT_ID; if (i == list.Count - 1) { dto.DeptID += deptid; dto.DeptName += _Dept.FirstOrDefault(x => x.C_ID == deptid).C_NAME; } else { dto.DeptID += list[i].C_DEPT_ID + ","; dto.DeptName += _Dept.FirstOrDefault(x => x.C_ID == deptid).C_NAME + ","; } } } return(dto); }
/// <summary> /// 获取用户列表(分页) /// </summary> /// <param name="uDto"></param> /// <returns></returns> public PageResult <TS_USER> GetUsers(TS_USERDTO uDto) { Expression <Func <TS_USER, bool> > where = null; where = where.And <TS_USER>(x => x.N_STATUS == 1); where = where.And <TS_USER>(x => x.N_TYPE != 3); if (!string.IsNullOrWhiteSpace(uDto.C_NAME)) { where = where.And <TS_USER>(x => x.C_NAME.Contains(uDto.C_NAME)); } if (!string.IsNullOrWhiteSpace(uDto.C_ACCOUNT)) { where = where.And <TS_USER>(x => x.C_ACCOUNT.Contains(uDto.C_ACCOUNT)); } if (!string.IsNullOrWhiteSpace(uDto.C_SHORTNAME)) { where = where.And <TS_USER>(x => x.C_SHORTNAME.Contains(uDto.C_SHORTNAME)); } Expression <Func <TS_USER, DateTime> > order = null; order = t => t.D_LASTLOGINTIME ?? DateTime.Now; return(QueryPage <TS_USER, DateTime>(where, uDto.BasePage.PageSize, uDto.BasePage.PageIndex, order)); }
/// <summary> /// 获取用户部门信息 /// </summary> /// <param name="dto"></param> /// <returns></returns> public TS_USERDTO GetDept(TS_USERDTO dto) { if (dto.Users.Count > 0) { foreach (var user in dto.Users) { List <TS_USER_DEPT> list = _UserDept.Where(x => x.C_USER_ID.Equals(user.C_ACCOUNT)).ToList(); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { string deptid = list[i].C_DEPT_ID; if (i == list.Count - 1) { user.DeptID += deptid; user.DeptName += _Dept.FirstOrDefault(x => x.C_ID == deptid).C_NAME; } else { user.DeptID += list[i].C_DEPT_ID + ","; user.DeptName += _Dept.FirstOrDefault(x => x.C_ID == deptid).C_NAME + ","; } } } } } return(dto); }
/// <summary> /// 用户新增 /// </summary> /// <returns></returns> public ActionResult UserInsert() { TS_USERDTO dto = new TS_USERDTO(); dto.Title = "用户添加"; return(View(dto)); }
public ActionResult UserManage(TS_USERDTO dto) { //获取完成工差列表 PageResult <TS_USER> ef = service.GetUsers(dto, 1); //获取分页数据 BASEPAGE page = AUTOMAPING.Mapping <BASEPAGE>(ef); this.HttpContext.Session["Page"] = page; //EF实体数据转换为DTO dto.Users = MAPPING.ConvertEntityToDtoList <TS_USER, TS_USERDTO>(ef.DataList); //获取客户档案 foreach (var item in dto.Users) { if (item.C_CUST_ID != null) { item.CustFile = basicsService.GetCustFile(item.C_CUST_ID); } else { item.CustFile = new TS_CUSTFILE(); } } //角色列表 dto.Roles = basicsService.GetRoleDropDown(); //获取部门 dto = service.GetDept(dto); return(View(dto)); }
public ActionResult UserUpdate(TS_USERDTO dto) { //验证数据模型 if (!ModelState.IsValid) { return(View(dto)); } //用户是否重复 if (service.UserLogin(dto.C_ACCOUNT, dto.C_ID) != null) { ModelState.AddModelError("error", "登录名重复"); return(View(dto)); } else { dto.C_EMP_ID = BaseUser.Id; dto.C_EMP_NAME = BaseUser.Name; dto.D_MOD_DT = DateTime.Now; TS_USER user = AutoMapper.Mapper.Map <TS_USER>(dto); //修改用户 service.UserUpdate(user); //部门信息更新 service.DeptOperation(dto); dto.ResultType = 1; return(View(dto)); } }
/// <summary> /// 用户修改 /// </summary> /// <returns></returns> public ActionResult UserUpdate(string id) { TS_USERDTO dto = new TS_USERDTO(); dto.Title = "用户修改"; dto = service.Get(id); return(View(dto)); }
public ActionResult QueryUser(TS_USERDTO uDto) { PageResult <TS_USER> ef = service.GetUsers(uDto); BASEPAGE page = AUTOMAPING.Mapping <BASEPAGE>(ef); this.HttpContext.Session["Page"] = page; uDto.Users = MAPPING.ConvertEntityToDtoList <TS_USER, TS_USERDTO>(ef.DataList); return(View(uDto)); }
/// <summary> /// 获取用户列表(分页) /// </summary> /// <param name="uDto"></param> /// <param name="type"></param> /// <returns></returns> public PageResult <TS_USER> GetUsers(TS_USERDTO uDto, int type) { string table = " TS_USER T "; string order = "T.D_MOD_DT desc"; string where = @" AND T.N_TYPE!=3 "; if (!string.IsNullOrWhiteSpace(uDto.RoleID)) { table += "LEFT JOIN TS_USER_ROLE UR ON T.C_ID = UR.C_USER_ID"; where += string.Format(" AND UR.C_ROLE_ID='{0}' ", uDto.RoleID); } if (!string.IsNullOrWhiteSpace(uDto.C_NAME)) { uDto.C_NAME = uDto.C_NAME.Trim(); where += string.Format(" AND ( T.C_NAME like '%{0}%' or T.C_ACCOUNT like '%{1}%' )", uDto.C_NAME, uDto.C_NAME); } if (uDto.N_STATUS != 0) { where += " AND T.N_STATUS=" + uDto.N_STATUS; } if (!string.IsNullOrWhiteSpace(uDto.C_SHORTNAME)) { where += string.Format(" AND T.C_SHORTNAME like '%{0}%' ", uDto.C_SHORTNAME); } if (uDto.N_TYPE != 0) { where += " AND T.N_TYPE=" + uDto.N_TYPE; } if (!string.IsNullOrWhiteSpace(uDto.C_ACCOUNT)) { where += string.Format(" AND T.C_ACCOUNT='{0}' ", uDto.C_ACCOUNT); } //总条数 int count = 0; //数据集合 var users = GenerateByPageSql <TS_USER>(uDto.BasePage.PageSize, uDto.BasePage.PageIndex, "t.* ", table, order, where, out count).ToList(); //转换为分页数据 PageResult <TS_USER> result = new PageResult <TS_USER>() { DataList = users, PageIndex = uDto.BasePage.PageIndex, PageSize = uDto.BasePage.PageSize, TotalCount = count }; //计算页数 BaseService.CalculatePage <TS_USER>(result.PageSize, result); return(result); }
/// <summary> /// 查询用户 /// </summary> /// <param name="queryType">查询类型1 多选 0单选</param> /// <param name="htmlApproveId">html审批人标记id</param> /// <returns></returns> public ActionResult QueryUser(int queryType, string htmlApproveId, string htmlApproveName) { TS_USERDTO uDto = new TS_USERDTO(); PageResult <TS_USER> ef = service.GetUsers(uDto); BASEPAGE page = AUTOMAPING.Mapping <BASEPAGE>(ef); this.HttpContext.Session["Page"] = page; uDto.Users = MAPPING.ConvertEntityToDtoList <TS_USER, TS_USERDTO>(ef.DataList); uDto.C_QueryType = queryType; uDto.HtmlApproveId = htmlApproveId; uDto.HtmlApproveName = htmlApproveName; return(View(uDto)); }
/// <summary> /// 部门信息操作 /// </summary> public void DeptOperation(TS_USERDTO dto) { TS_USER user = _UserMenu.FirstOrDefault(x => x.C_ACCOUNT.Equals(dto.C_ACCOUNT)); if (user != null && user.C_ID != null) { List <TS_USER_DEPT> list = _UserDept.Where(x => x.C_USER_ID.Equals(user.C_ACCOUNT)).ToList(); this.Delete <TS_USER_DEPT>(list); if (dto.DeptID != null) { string[] arr = dto.DeptID.Split(','); foreach (var item in arr) { TS_USER_DEPT userDept = new TS_USER_DEPT(); userDept.C_USER_ID = user.C_ACCOUNT; userDept.C_DEPT_ID = item; this.Insert(userDept); } } } }
public ActionResult UserInsert(TS_USERDTO dto) { dto.Title = "用户添加"; //验证数据模型 if (!ModelState.IsValid) { return(View(dto)); } //用户是否重复 if (service.GetUser(dto.C_ACCOUNT) != null) { ModelState.AddModelError("error", "登录名重复"); return(View(dto)); } else { if (!string.IsNullOrWhiteSpace(dto.C_ACCOUNT)) { dto.C_ACCOUNT = dto.C_ACCOUNT.Trim(); } if (!string.IsNullOrWhiteSpace(dto.C_PASSWORD)) { dto.C_PASSWORD = Encrypt.MD5(dto.C_PASSWORD.Trim()); } dto.C_EMP_ID = BaseUser.Id; dto.C_EMP_NAME = BaseUser.Name; dto.D_MOD_DT = DateTime.Now; TS_USER user = AutoMapper.Mapper.Map <TS_USER>(dto); //用户类别1客户 2内部 user.N_TYPE = 2; //新增用户 service.UserInsert(user); //部门信息更新 service.DeptOperation(dto); dto.ResultType = 1; return(View(dto)); } }
public ActionResult Register() { TS_USERDTO userDto = new TS_USERDTO(); return(View(userDto)); }