public ActionResult AddCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser propertyUser = new T_CompanyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, CompanyId = GetSessionModel().CompanyId.Value }; // 保存到数据库 companyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadHeadPic(int id) { JsonModel jm = new JsonModel(); //获取要上传头像的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //用户存在 if (companyUser != null) { LoggedInAccountModel userModel = new LoggedInAccountModel() { UserId = companyUser.Id, HeadPath = companyUser.HeadPath }; return(View(userModel)); } //用户不存在 else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ResetPassword(int?id) { JsonModel jm = new JsonModel(); //参数校验 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ICompanyUserBLL companyUserBLL = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); // 根据指定id值获取实体对象 var companyUserInfo = companyUserBLL.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUserInfo != null) { Random r = new Random(); int radVal = r.Next(100, 1000); companyUserInfo.Password = PropertyUtils.GetMD5Str(companyUserInfo.UserName + radVal); // 恢复初始密码值 companyUserBLL.Update(companyUserInfo); // 给物业总公司用户发送邮件 PropertyUtils.SendEmail(companyUserInfo.Email, companyUserInfo.UserName, "物业总公司管理系统 用户密码重置", "您的用户密码已重置为" + companyUserInfo.UserName + radVal + ", 请及时修改密码!"); //操作日志 jm.Content = "物业总公司用户" + companyUserInfo.TrueName + "密码一键重置成功"; } else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult SetUserInfo() { //获取当前用户 UserSessionModel model = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = model.UserID; ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var companyUser = companyUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { LoggedInAccountModel companyUserModel = new LoggedInAccountModel(); companyUserModel.UserId = companyUser.Id; companyUserModel.UserName = companyUser.UserName; companyUserModel.TrueName = companyUser.TrueName; companyUserModel.Phone = companyUser.Phone; companyUserModel.Email = companyUser.Email; companyUserModel.Memo = companyUser.Memo; companyUserModel.HeadPath = companyUser.HeadPath; return(View(companyUserModel)); } else { return(RedirectToAction("Index", "CompanyPlatform")); } }
public ActionResult EditUserPwd(AccountPasswordChangeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { //获取要修改密码的用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.Password = PropertyUtils.GetMD5Str(model.Password); // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ScanRole(int id) { // 创建物业总公司用户角色模型 CompanyUserRoleModel companyUserRoleModel = new CompanyUserRoleModel(); ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); // 根据指定id值获取实体对象 var companyUserInfo = companyUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); companyUserRoleModel.User = new CompanyUserModel() { UserName = companyUserInfo.UserName, CompanyUserId = companyUserInfo.Id, TrueName = companyUserInfo.TrueName }; // 获取物业总公司用户已分配的角色id列表 var selectedRoleList = companyUserInfo.CompanyUserRoles.Select(m => m.RoleId).ToList(); companyUserRoleModel.RoleIds = selectedRoleList; // 获取所有物业总公司角色 ICompanyRoleBLL companyRoleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); //排序 var sortModel = this.SettingSorting("Id", false); var roleList = companyRoleBll.GetList(p => true, sortModel.SortName, sortModel.IsAsc).ToList(); companyUserRoleModel.RoleList = roleList; return(View(companyUserRoleModel)); }
/// <summary> /// 删除公司,删除其角色和用户 /// </summary> /// <param name="company">公司实体对象</param> /// <returns></returns> public bool DeleteCompany(T_Company company) { //使用事务进行数据库操作 using (var tran = this.nContext.Database.BeginTransaction()) { try { //修改为删除标识 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var users = companyUserBll.GetList(u => u.CompanyId == company.Id && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT).ToList(); foreach (var user in users) { user.DelFlag = ConstantParam.DEL_FLAG_DELETE; companyUserBll.Update(user); } //改为删除标识 base.Update(company); //提交事务 tran.Commit(); } catch { tran.Rollback(); return(false); } } return(true); }
/// <summary> /// 删除指定物业总公司用户 /// </summary> /// <returns></returns> public ActionResult DeleteCompanyUser(int?id) { JsonModel jm = new JsonModel(); //参数校验 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); // 根据指定id值获取实体对象 var companyUserInfo = companyUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUserInfo != null) { // 修改指定用户记录中的已删除标识 companyUserInfo.DelFlag = ConstantParam.DEL_FLAG_DELETE; companyUserBll.Update(companyUserInfo); //操作日志 jm.Content = "删除物业用户 " + companyUserInfo.TrueName; } else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult CompanyPlatformLogin(AccountModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } string code = (string)Session["ValidateCode"]; if (model.CheckCode != code) { ModelState.AddModelError("CheckCode", "验证码不正确"); return(View(model)); } //根据用户名查找用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser user = companyUserBll.GetEntity(u => u.UserName == model.UserName.Trim() && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View(model)); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { ModelState.AddModelError("Password", "密码不正确"); return(View(model)); } //3.如果未设置角色 if (user.CompanyUserRoles.Count == 0) { ModelState.AddModelError("UserName", "该用户未设置角色,请联系管理员"); return(View(model)); } //4.获取用户对象信息(权限菜单,Action等)保存基本信息到session中 this.SetUserSessiong(user, companyUserBll); //5.判断是否拥有访问首页的权限 UserSessionModel session = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; if (session.IsMgr == ConstantParam.USER_ROLE_DEFAULT && !session.ActionDic.ContainsKey("/CompanyPlatform/Index")) { ModelState.AddModelError("UserName", "该用户无访问权限,请联系管理员"); return(View(model)); } BreadCrumb.ClearState(); //5.跳转到 return(RedirectToAction("Index", "CompanyPlatform")); }
public ActionResult UploadHeadPic(string data, int userId) { JsonModel jm = new JsonModel(); //保存头像文件 string directory = Server.MapPath(ConstantParam.COMPANY_USER_HEAD_DIR); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var fileName = DateTime.Now.ToFileTime().ToString() + ".jpg"; var path = Path.Combine(directory, fileName); using (FileStream fs = new FileStream(path, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] datas = Convert.FromBase64String(data); bw.Write(datas); bw.Close(); } } //获取要上传头像的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //用户存在 if (companyUser != null) { string oldFile = companyUser.HeadPath; companyUser.HeadPath = ConstantParam.COMPANY_USER_HEAD_DIR + fileName; companyUserBll.Update(companyUser); //更新SessionModel中的最新个人信息 UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; sessionModel.HeadPath = ConstantParam.COMPANY_USER_HEAD_DIR + fileName; //删除旧头像 if (!string.IsNullOrEmpty(oldFile)) { oldFile = Server.MapPath(oldFile); FileInfo f = new FileInfo(oldFile); if (f.Exists) { f.Delete(); } } } //用户不存在 else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult CompanyUserList(SearchModel model) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); //所属总公司 int companyId = GetSessionModel().CompanyId.Value; Expression <Func <T_CompanyUser, bool> > where = u => (string.IsNullOrEmpty(model.Kword) ? true : (u.TrueName.Contains(model.Kword) || u.UserName.Contains(model.Kword))) && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.CompanyId == companyId; //排序 var sortModel = this.SettingSorting("Id", false); var list = companyUserBll.GetPageList(where, sortModel.SortName, sortModel.IsAsc, model.PageIndex); return(View(list)); }
public ContentResult RemoteUserCheckExist(string userName) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); // 用户名已存在 if (companyUserBll.Exist(m => m.UserName == userName && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT)) { // 校验不通过 return(Content("false")); } else { return(Content("true")); } }
public JsonResult SetCompanyAdministrator(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL propertyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = new T_CompanyUser() { CompanyId = model.CompanyId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 ICompanyRoleBLL roleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.CompanyId == model.CompanyId); if (role != null) { companyUser.CompanyUserRoles.Add(new R_CompanyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditCompanyUser(int?id) { // 参数校验 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var companyUserInfo = companyUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUserInfo != null) { CompanyUserModel companyUserModel = new CompanyUserModel(); companyUserModel.CompanyUserId = companyUserInfo.Id; companyUserModel.UserName = companyUserInfo.UserName; companyUserModel.TrueName = companyUserInfo.TrueName; companyUserModel.Memo = companyUserInfo.Memo; companyUserModel.Tel = companyUserInfo.Tel; companyUserModel.Phone = companyUserInfo.Phone; companyUserModel.Email = companyUserInfo.Email; companyUserModel.HeadPath = companyUserInfo.HeadPath; companyUserModel.CompanyId = GetSessionModel().CompanyId.Value; // 获取指定小区的名称 IPropertyCompanyBLL propertyCompanyBll = BLLFactory <IPropertyCompanyBLL> .GetBLL("PropertyCompanyBLL"); var propertyCompany = propertyCompanyBll.GetEntity(m => m.Id == companyUserModel.CompanyId); if (propertyCompany != null) { companyUserModel.CompanyName = propertyCompany.Name; } return(View(companyUserModel)); } else { return(RedirectToAction("UserList")); } }
public ActionResult SetUserInfo(LoggedInAccountModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { //获取要编辑个人信息的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.TrueName = model.TrueName; companyUser.Phone = model.Phone; companyUser.Email = model.Email; companyUser.Memo = model.Memo; // 保存到数据库 companyUserBll.Update(companyUser); //更新SessionModel中的最新个人信息 UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; sessionModel.TrueName = model.TrueName; //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditUserPwd() { UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = sessionModel.UserID; //获取要修改密码的总公司用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { AccountPasswordChangeModel model = new AccountPasswordChangeModel(); model.UserId = companyUser.Id; model.UserName = companyUser.UserName; return(View(model)); } else { return(RedirectToAction("Index", "CompanyPlatform")); } }
/// <summary> /// 获取当前登录用户的头像图片路径 /// </summary> /// <param name="html">HTML对象</param> /// <returns></returns> public static string GetLoginUserHeadImgPath(this HtmlHelper html) { //获取session对象 var session = HttpContext.Current.Session; var model = (UserSessionModel)session[ConstantParam.SESSION_USERINFO]; if (model != null) { if (model.UserType == ConstantParam.USER_TYPE_PROPERTY) { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); return(user.HeadPath); } else if (model.UserType == ConstantParam.USER_TYPE_SHOP) { IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); return(user.HeadPath); } else if (model.UserType == ConstantParam.USER_TYPE_PLATFORM) { IPlatformUserBLL userBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); return(user.HeadPath); } else if (model.UserType == ConstantParam.USER_TYPE_COMPANY) { ICompanyUserBLL userBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); return(user.HeadPath); } } return(null); }
public ActionResult EditCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.CompanyUserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.UserName = model.UserName; companyUser.TrueName = model.TrueName; companyUser.Memo = model.Memo; companyUser.Tel = model.Tel; companyUser.Phone = model.Phone; companyUser.Email = model.Email; // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfigRole(int id) { // 创建物业总公司用户角色模型 CompanyUserRoleModel companyUserRoleModel = new CompanyUserRoleModel(); // 获取指定id的物业总公司用户模型 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); companyUserRoleModel.User = new CompanyUserModel() { CompanyUserId = companyUser.Id, UserName = companyUser.UserName, TrueName = companyUser.TrueName, Tel = companyUser.Tel, Phone = companyUser.Phone, Memo = companyUser.Memo, Email = companyUser.Email }; // 获取本总公司中所有的角色 ICompanyRoleBLL companyRoleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); //排序 var sortModel = this.SettingSorting("Id", false); var roleList = companyRoleBll.GetList(p => p.CompanyId == companyUser.CompanyId && p.IsSystem == ConstantParam.USER_ROLE_DEFAULT, sortModel.SortName, sortModel.IsAsc).ToList(); companyUserRoleModel.RoleList = roleList; //获取该总公司用户已分配的角色id的集合 companyUserRoleModel.RoleIds = companyUser.CompanyUserRoles.Select(m => m.RoleId).ToList(); return(View(companyUserRoleModel)); }
public ActionResult ConfigRole(CompanyUserConfigRoleModel model) { JsonModel jm = new JsonModel(); ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); //获取要分配角色的物业总公司用户 T_CompanyUser user = companyUserBll.GetEntity(m => m.Id == model.userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); // 新建物业总公司用户角色关联表 List <R_CompanyUserRole> roles = new List <R_CompanyUserRole>(); if (model.ids != null) { //没有设置任何角色 则不执行循环操作 foreach (var id in model.ids) { R_CompanyUserRole item = new R_CompanyUserRole() { UserId = model.userId, RoleId = id }; roles.Add(item); } } //修改物业用户对应的角色集合 if (companyUserBll.ConfigRole(user, roles)) { jm.Content = "物业用户 " + user.TrueName + " 分配角色"; } else { jm.Msg = "分配角色失败"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadPic(int id) { JsonModel jm = new JsonModel(); ICompanyUserBLL UserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var companyUser = UserBll.GetEntity(m => m.DelFlag == 0 && m.Id == id); //总公司用户存在 if (companyUser != null) { CompanyUserModel userModel = new CompanyUserModel() { CompanyUserId = companyUser.Id, HeadPath = companyUser.HeadPath }; return(View(userModel)); } //用户不存在 else { jm.Msg = "用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 保存总公司用户的session信息 /// </summary> /// <param name="user"></param> private void SetUserSessiong(T_CompanyUser user, ICompanyUserBLL bll) { //用户session模型 UserSessionModel sessionInfo = new UserSessionModel(); //设置基本信息 sessionInfo.UserID = user.Id; sessionInfo.UserName = user.UserName; sessionInfo.TrueName = user.TrueName; sessionInfo.IsMgr = user.IsMgr; sessionInfo.UserType = ConstantParam.USER_TYPE_COMPANY; sessionInfo.CompanyId = user.CompanyId; sessionInfo.HeadPath = user.HeadPath; //构造菜单业务对象 IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); #region 设置总公司用户菜单以及权限 //管理员 if (user.IsMgr == ConstantParam.USER_ROLE_MGR) { //获取菜单 var list = menuBll.GetList(m => m.MenuFlag == ConstantParam.MENU_LEFT && m.IsPlatform == ConstantParam.USER_TYPE_COMPANY).Select(m => new MenuModel { MenuId = m.Id, MenuName = m.MenuName, MenuCode = m.MenuCode, MenuUrl = m.Href, MenuFlag = m.MenuFlag, MenuCss = m.IconClass, ParentId = m.ParentId, Order = m.Order, IsPlatform = m.IsPlatform }).ToList(); //设置左边菜单 sessionInfo.MenuList = list; } else { //获取总公司用户对应的角色权限表 var roleActions = user.CompanyUserRoles.Select(ur => ur.CompanyRole.CompanyRoleActions); //菜单字典 Dictionary <string, MenuModel> menuDic = new Dictionary <string, MenuModel>(); //权限字典 Dictionary <string, string> actionDic = new Dictionary <string, string>(); foreach (var item in roleActions) { var actions = item.Select(obj => obj.Action); foreach (var action in actions) { //添加权限 if (!actionDic.ContainsKey(action.Href)) { actionDic.Add(action.Href, action.ActionName); } foreach (var li in action.ActionItems) { //添加权限 if (!actionDic.ContainsKey(li.Href)) { actionDic.Add(li.Href, li.ItemName); } } var menu = action.Menu; if (menu.ParentId != null) { if (!menuDic.ContainsKey(menu.ParentMenu.MenuCode)) { menuDic.Add(menu.ParentMenu.MenuCode, GetMenuModel(menu.ParentMenu)); } } if (!menuDic.ContainsKey(menu.MenuCode)) { menuDic.Add(menu.MenuCode, GetMenuModel(menu)); } } } //设置菜单和权限 sessionInfo.MenuList.AddRange(menuDic.Values.ToList()); sessionInfo.ActionDic = actionDic; } #endregion //设置session信息 Session[ConstantParam.SESSION_USERINFO] = sessionInfo; }
/// <summary> /// 获取当前登录用户的名字 /// </summary> /// <param name="html">HTML对象</param> /// <returns></returns> public static string GetLoginUserName(this HtmlHelper html) { string name = ""; //获取session对象 var session = HttpContext.Current.Session; var model = (UserSessionModel)session[ConstantParam.SESSION_USERINFO]; if (model != null) { if (model.UserType == ConstantParam.USER_TYPE_PROPERTY) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); var user = propertyUserBll.GetEntity(u => u.Id == model.UserID); if (!string.IsNullOrEmpty(user.TrueName)) { name = user.TrueName; } else { name = user.UserName; } } else if (model.UserType == ConstantParam.USER_TYPE_SHOP) { IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL"); var user = shopUserBll.GetEntity(u => u.Id == model.UserID); if (!string.IsNullOrEmpty(user.TrueName)) { name = user.TrueName; } else { name = user.UserName; } } else if (model.UserType == ConstantParam.USER_TYPE_PLATFORM) { IPlatformUserBLL userBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); if (!string.IsNullOrEmpty(user.TrueName)) { name = user.TrueName; } else { name = user.UserName; } } else if (model.UserType == ConstantParam.USER_TYPE_COMPANY) { ICompanyUserBLL userBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserID); if (!string.IsNullOrEmpty(user.TrueName)) { name = user.TrueName; } else { name = user.UserName; } } } return(name); }