public UserModel ValidateUser(string email, string password, bool isChecked) { User objuser = userRepository.SingleOrDefault(a => a.EmailId == email && a.RecordDeleted == false && a.Active == true && a.Company.IsActive == true); if (objuser != null && string.Compare(objuser.Password, password) == 0) { UserModel userModel = new UserModel(); AutoMapper.Mapper.Map(objuser, userModel); AutoMapper.Mapper.Map(objuser.Company, userModel.CompanyModel); AutoMapper.Mapper.Map(objuser.Profile, userModel.ProfileModel); AutoMapper.Mapper.Map(objuser.CultureInformation, userModel.CultureInformationModel); AutoMapper.Mapper.Map(objuser.TimeZone, userModel.TimeZoneModel); List <ProfilePermissionModel> profilePermissionModels = new List <ProfilePermissionModel>(); AutoMapper.Mapper.Map(objuser.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; ModulePermissionModel modulePermissionModel = new ModulePermissionModel(); AutoMapper.Mapper.Map(objuser.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; return(userModel); } return(null); }
public ActionResult GetPermission(int roleId, string selectedModules) { //选中模块 List <int> selectedModuleId = new List <int>(); string[] strSelectedModules = selectedModules.Split(','); foreach (var Id in strSelectedModules) { selectedModuleId.Add(Convert.ToInt32(Id)); } //权限列表 var model = new RoleSelectedPermissionModel(); model.HeaderPermissionList = PermissionService.Permissions.Where(t => t.IsDeleted == false && t.Enabled == true) .OrderBy(t => t.OrderSort) .Select(t => new PermissionModel { PermissionId = t.Id, PermissionName = t.Name, OrderSort = t.OrderSort }).ToList(); //权限列表 (从选中的菜单获取) foreach (var moduleId in selectedModuleId.Distinct()) { var module = ModuleService.Modules.FirstOrDefault(t => t.Id == moduleId); var modulePermissionModel = new ModulePermissionModel { ModuleId = module.Id, ParentId = module.ParentId, ModuleName = module.Name, Code = module.Code }; //所有权限列表 foreach (var permission in model.HeaderPermissionList) { modulePermissionModel.PermissionDataList.Add(new PermissionModel { PermissionId = permission.PermissionId, PermissionName = permission.PermissionName, OrderSort = permission.OrderSort, }); } //模块包含的按钮 var modulePermission = ModulePermissionService.ModulePermissions.Where(t => t.ModuleId == moduleId && t.IsDeleted == false); var selectedModulePermission = RoleModulePermissionService.RoleModulePermissions.Where(t => t.RoleId == roleId && t.ModuleId == moduleId && t.IsDeleted == false); if (module.ChildModule.Count > 0 && selectedModulePermission.Count() > 0) { modulePermissionModel.Selected = true; } foreach (var mp in modulePermission) { var permission = PermissionService.Permissions.FirstOrDefault(t => t.Id == mp.PermissionId); foreach (var p in modulePermissionModel.PermissionDataList) { if (p.PermissionId == permission.Id) { //设置Checkbox可用 p.Enabled = true; //设置选中 var rmp = RoleModulePermissionService.RoleModulePermissions.FirstOrDefault(t => t.RoleId == roleId && t.ModuleId == moduleId && t.PermissionId == permission.Id && t.IsDeleted == false); if (rmp != null) { //设置父节点选中 modulePermissionModel.Selected = true; p.Selected = true; } } } } model.ModulePermissionDataList.Add(modulePermissionModel); } //权限按照Code排序 model.ModulePermissionDataList = model.ModulePermissionDataList.OrderBy(t => t.Code).ToList(); return(PartialView("Permission", model)); }
public ActionResult GetPermission(string roleId, string selectedModules) { //选中模块 List <string> selectedModuleId = new List <string>(); string[] strSelectedModules = selectedModules.Split(','); foreach (var Id in strSelectedModules) { selectedModuleId.Add(Id); } //权限模块列表 var model = new RoleSelectedPermissionModel(); //权限下的模块 var role = RoleService.Roles.Where(t => t._ID == roleId && t.IsDeleted == false).FirstOrDefault(); if (role != null) { var permissions = PermissionService.Permissions.Where(t => t.IsDeleted == false && t.Enabled == true) .OrderBy(t => t.OrderSort).ToList() .Select(t => new PermissionModel { Enabled = t.Enabled, PermissionId = t._ID, PermissionName = t.Name, OrderSort = t.OrderSort }).ToList(); model.HeaderPermissionList = permissions; var module = ModuleService.Modules.Where(t => selectedModuleId.Contains(t._ID)).ToList(); foreach (var m in module) { var modulePermissionModel = new ModulePermissionModel { ModuleId = m._ID, ParentId = m.ParentId, ModuleName = m.Name, Code = m.Code }; var rmodule = new RoleModulePermission(); if (role.RoleModulePermissions != null) { rmodule = role.RoleModulePermissions.FirstOrDefault(x => x.ModuleId == m._ID); } if (rmodule == null) { rmodule = new RoleModulePermission(); } rmodule.PermissionIds = rmodule.PermissionIds ?? new List <string>(); foreach (var p in permissions) { var selected = rmodule.PermissionIds.FirstOrDefault(x => x == p.PermissionId) != null; if (selected && !modulePermissionModel.Selected) { modulePermissionModel.Selected = true; var pa = model.ModulePermissionDataList.FirstOrDefault(x => x.ModuleId == modulePermissionModel.ParentId); if (pa != null && !pa.Selected) { pa.Selected = true; } } modulePermissionModel.PermissionDataList.Add(new PermissionModel { PermissionId = p.PermissionId, PermissionName = p.PermissionName, OrderSort = p.OrderSort, Enabled = m.PermissionIds.FirstOrDefault(x => x == p.PermissionId) != null, Selected = selected }); } model.ModulePermissionDataList.Add(modulePermissionModel); } //权限按照Code排序 model.ModulePermissionDataList = model.ModulePermissionDataList.OrderBy(t => t.Code).ToList(); } return(PartialView("Permission", model)); }
public UserModel RegisterUser(UserModel userModel) { User user = new User(); user.Company = new Company(); AutoMapper.Mapper.Map(userModel, user); user.CreatedDate = DateTime.UtcNow; user.Active = true; user.ProfileId = GetDefaultRegistertedUserProfileId();//(int)Enums.Profile.Administrator; user.UserTypeId = (int)Enums.UserType.User; user.RoleId = roleRepository.SingleOrDefault(x => x.IsDefaultForRegisterdUser == true && x.RecordDeleted == false).RoleId; user.Address = null; user.Profile = null; user.Role = null; user.Company.CreatedOn = DateTime.UtcNow; user.Company.IsActive = true; if (user.CultureInformationId == 0) { user.CultureInformationId = null; } if (user.TimezoneId == 0) { user.TimezoneId = null; } userRepository.Insert(user); UserSetting userSetting = new UserSetting(); userSetting.IsSendNotificationsRecentActivities = true; userSetting.UserId = user.UserId; accountRepository.Insert(userSetting); //Add the default stage for newly created company of registered user List <Stage> listDefaultStages = stageRepositry.GetAll(x => x.CompanyId == null).ToList(); for (int i = 0; i < listDefaultStages.Count; i++) { Stage objDefaultStage = new Stage(); objDefaultStage = listDefaultStages[i]; objDefaultStage.CompanyId = user.CompanyId; if (objDefaultStage.IsInitialStage == true) { objDefaultStage.StageOrder = 0; } else if (objDefaultStage.IsLastStage == true) { objDefaultStage.StageOrder = 100; } stageRepositry.Insert(objDefaultStage); } user = userRepository.SingleOrDefault(r => r.UserId == user.UserId); AutoMapper.Mapper.Map(user, userModel); //Code Added by mahesh bhatt for loading a user after register with full permission AutoMapper.Mapper.Map(user.Company, userModel.CompanyModel); AutoMapper.Mapper.Map(user.Profile, userModel.ProfileModel); AutoMapper.Mapper.Map(user.CultureInformation, userModel.CultureInformationModel); List <ProfilePermissionModel> profilePermissionModels = new List <ProfilePermissionModel>(); AutoMapper.Mapper.Map(user.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; ModulePermissionModel modulePermissionModel = new ModulePermissionModel(); AutoMapper.Mapper.Map(user.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; /////////////////////////////////////// profileRepository.CreateDefaultStandardProfile(user.CompanyId); return(userModel); }