Exemplo n.º 1
0
 public EditUserModel InitializeEditUserModel(Guid? id)
 {
     var model = new EditUserModel();
     if (id.HasValue)
     {
         var user = _userRepository.Find(id.Value);
         model.FormData.Account = user.Account;
         model.FormData.DepartmentId = user.Department != null ? user.Department.Id : default(Guid?);
         model.FormData.Mobile = user.PhoneBookRecord != null ? user.PhoneBookRecord.Mobile : string.Empty;
         model.FormData.Name = user.Name;
         model.FormData.QQ = user.QQ;
         model.FormData.OrderSort = user.OrderSort;
         var roleUserRepository = new RoleUserRepository();
         var roleUser = roleUserRepository.GetRoleUserByUserId(id.Value);
         if (roleUser != null)
             model.FormData.RoleNames = string.Join(",", roleUser.Roles.Select(o => o.Code));
     }
     var roleRepository = new RoleRepository();
     model.Roles = roleRepository.GetAllRoleByUnitId(NpcContext.CurrentUser.Unit.Id);
     return model;
 }
Exemplo n.º 2
0
 private void InitUnitPermissions(Unit unit, User admin)
 {
     var privilegeRepository = new PrivilegeRepository();
     var privileges = privilegeRepository.GetAllPrivileges();
     var roleRepository = new RoleRepository();
     var roles = roleRepository.GetAllRoleByUnitId(unit.Id);
     var role = roles.FirstOrDefault(r => r.Code == "SuperAdmin");
     if (role == null)
     {
         role = new Role();
         role.Name = "超级管理员";
         role.Code = "SuperAdmin";
         role.UnitId = unit.Id;
         privileges.ToList().ForEach(privilege => role.Privileges.Add(privilege));
         roleRepository.Save(role);
     }
     var roleUserRepository = new RoleUserRepository();
     var roleUser = roleUserRepository.GetRoleUserByUserId(admin.Id);
     if (roleUser == null)
     {
         roleUser = new RoleUser();
         roleUser.UserId = admin.Id;
         roleUser.Roles.Add(role);
         roleUserRepository.Save(roleUser);
     }
 }