private void SeedUserRoleType(DataContext context) { List <string> items = new List <string>() { "CRO", "AVP", "CEO", "DBD", "CL", "CAC", "PU", "MC", "SLH", "CU", "CBO", "NCM", "IT" }; foreach (string item in items) { var entity = context.UserRoleTypes.Where(p => p.Name == item && p.Deleted == false).SingleOrDefault(); if (entity == null) { entity = new UserRoleType(); entity.Name = item; context.UserRoleTypes.Add(entity); } } }
public void AssignRoleToUser(ApplicationUser user, UserRoleType userRole) { if (!_userManager.IsInRoleAsync(user, userRole.ToString()).Result) { _userManager.AddToRoleAsync(user, userRole.ToString()).Wait(); } }
private void GetRoleType(int userId) { UserRoleType userRoleType = new UserRoleType(); userRoleType.Attach(this); userRoleType.GetUserRoleId(userId); }
public static void AttachRole(User user, UserRoleType role) { var userStore = new UserStore <User>(new CaiDbContext()); var userManager = new UserManager <User>(userStore); userManager.AddToRole(user.Id, role.ToString()); }
public void Test1() { UserRoleType.findAll(typeof(UserRoleType)).ForEach(userRole => { Assert.True(userRole.name.Equals(dbContext.userRoleTypes.Single(u => u.value == userRole.value).name)); _testOutputHelper.WriteLine(userRole.name + " : " + userRole.value); }); }
public User() { this.UserID = 0; this.Username = ""; this.Encrypted = ""; this.CreateDate = new DateTime(1900, 1, 1); this.ModifyDate = new DateTime(1900, 1, 1); this.LastLogin = new DateTime(1900, 1, 1); this.UserRoleTypeID = UserRoleType.Unassigned; }
/// <summary> /// Check whether the user has any of the allowed roles to access given functionality. /// </summary> /// <param name="user">User account with roles.</param> /// <param name="requiredRole">Required user role.</param> /// <exception cref="InsufficientRoleException">is thrown when the user doesn't have any role specified by <see cref="allowedRoles"/></exception> internal static void CheckUserRole(AdaptorUser user, UserRoleType requiredUserRole) { bool hasRequiredRole = user.Roles.Any(userRole => (UserRoleType)userRole.Id == requiredUserRole); if (!hasRequiredRole) { using var unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork(); var requiredRoleModel = unitOfWork.AdaptorUserRoleRepository.GetById((long)requiredUserRole); throw InsufficientRoleException.CreateMissingRoleException(requiredRoleModel, user.Roles); } }
public Client(Guid id, string firstName, string lastName, string cpf, string email, string username, string password, UserRoleType role, bool isActive) { Id = id; FirstName = firstName; LastName = lastName; Cpf = cpf; Email = email; Username = username; Password = password; Role = role; IsActive = isActive; }
public Client(string firstName, string lastName, string cpf, string email, string username, string password, UserRoleType role) { Id = Guid.NewGuid(); FirstName = firstName; LastName = lastName; Cpf = cpf; Email = email; Username = username; Password = password; Role = role; IsActive = true; CreatedOn = DateTime.Now; }
public void UpdateClient(Client client) { Id = client.Id; FirstName = client.FirstName; LastName = client.LastName; Cpf = client.Cpf; Email = client.Email; Username = client.Username; Password = client.Password; Role = client.Role; IsActive = client.IsActive; UpdatedOn = DateTime.Now; }
public async Task <bool> HasRole(int id, UserRoleType urt) { var user = await GetUserById(id); if (user != null) { return(user.Roles.Any(r => r == (int)urt)); } else { return(false); } }
/// <summary> /// 根据Id获取 /// </summary> /// <param name="Id"></param> /// <returns></returns> public UserRoleType GetById(int Id) { UserRoleType obj = NSession.Get <UserRoleType>(Id); if (obj == null) { throw new Exception("返回实体为空"); } else { return(obj); } }
public ActionResult Edit(UserRoleType obj) { try { NSession.Update(obj); NSession.Flush(); } catch (Exception ee) { return(Json(new { IsSuccess = false, ErrorMsg = "出错了" })); } return(Json(new { IsSuccess = true })); }
public JsonResult DeleteConfirmed(int id) { try { UserRoleType obj = GetById(id); NSession.Delete(obj); NSession.Flush(); } catch (Exception ee) { return(Json(new { IsSuccess = false, ErrorMsg = "出错了" })); } return(Json(new { IsSuccess = true })); }
public async Task AddToRoleAsync(UserModel user, UserRoleType role) { using (var db = HibernateSession.GetCurrentSession()) { using (var tx = db.BeginTransaction()) { user = db.Get <UserModel>(user.Id); user.Roles.Add(new UserRole() { RoleType = role }); db.SaveOrUpdate(user); tx.Commit(); db.Flush(); } } }
public async Task <IList <string> > GetAuthorizedMenus(string role) { var menus = new List <string>(); var userRole = UserRoleType.Parse(typeof(UserRoleType), role); await Task.Run(() => { switch (userRole) { case UserRoleType.Admin: menus.Add("ClassRooms"); menus.Add("Classes"); menus.Add("Students"); menus.Add("Teachers"); menus.Add("Calenders"); menus.Add("CenterAdmins"); break; case UserRoleType.CenterAdmin: menus.Add("ClassRooms"); menus.Add("Classes"); menus.Add("Students"); menus.Add("Teachers"); menus.Add("Calenders"); break; case UserRoleType.Head: menus.Add("ClassRooms"); menus.Add("Calenders"); break; case UserRoleType.Student: menus.Add("MyCalender"); menus.Add("ClassRooms"); menus.Add("Classes"); break; case UserRoleType.Teacher: menus.Add("MyCalender"); menus.Add("ClassRooms"); menus.Add("Classes"); break; } }); return(menus.ToList()); }
public void Should_Throw_UserArgumentException_When_Removing_User_From_NonExisting_Role() { // Arrange string ldapName = "User123"; uint blueDeckId = 1; string firstName = "Bob"; string lastName = "Jones"; string idNumber = "1234"; string email = "*****@*****.**"; string contactNumber = "1234567890"; int rankId = 1; var user = new User(ldapName, blueDeckId, firstName, lastName, idNumber, email, contactNumber, rankId); var role = new UserRoleType { Name = "Administrator" }; // Act/Assert Assert.Throws <UserArgumentException>(() => user.RemoveFromRole(role)); }
public JsonResult UpdateUserRole(int id, UserRoleType role) { var user = _db.Users .Include(u => u.UserRoles) .Single(u => u.UserId == id); var uRole = user.UserRoles.First(); uRole.RoleType = role; var log = new UserLog(CurrentUser, id) { Comment = "Made " + uRole.RoleType.ToString() }; _db.UserLogs.Add(log); _db.Entry(uRole).State = System.Data.EntityState.Modified; _db.SaveChanges(); return(GetErrorMsgJSON()); }
public void Can_Add_User_To_Role() { // Arrange string ldapName = "User123"; uint blueDeckId = 1; string firstName = "Bob"; string lastName = "Jones"; string idNumber = "1234"; string email = "*****@*****.**"; string contactNumber = "1234567890"; int rankId = 1; var user = new User(ldapName, blueDeckId, firstName, lastName, idNumber, email, contactNumber, rankId); var role = new UserRoleType { Name = "Administrator" }; // Act user.AddToRole(role); // Assert Assert.Single(user.Roles); }
public async Task RemoveFromRoleAsync(UserModel user, UserRoleType role) { using (var db = HibernateSession.GetCurrentSession()) { using (var tx = db.BeginTransaction()) { user = db.Get <UserModel>(user.Id); var found = user.Roles.NotNull(y => y.ToList().FirstOrDefault(x => x.RoleType == role)); if (found != null) { found.DeleteTime = DateTime.UtcNow; db.Delete(found); user.Roles.Remove(found); } else { throw new PermissionsException("Role could not be removed because it doesn't exist."); } //user.Roles.Remove(found); //db.Update(user); tx.Commit(); db.Flush(); } } }
public async Task <bool> HasRole(int userId, UserRoleType urt) { var result = await _db.Include(u => u.RoleToUsers).ThenInclude(r => r.Role).SingleOrDefaultAsync(u => u.UserId == userId); return(result.RoleToUsers.Any(rtu => rtu.Role.UserRoleType == urt)); }
public JsonResult UpdateUserRole(int id, UserRoleType role) { var user = _db.Users .Include(u => u.UserRoles) .Single(u => u.UserId == id); var uRole = user.UserRoles.First(); uRole.RoleType = role; var log = new UserLog(CurrentUser, id) { Comment = "Made " + uRole.RoleType.ToString() }; _db.UserLogs.Add(log); _db.Entry(uRole).State = System.Data.EntityState.Modified; _db.SaveChanges(); return GetErrorMsgJSON(); }
public ActionResult Edit(int id) { UserRoleType obj = GetById(id); return(View(obj)); }
/// <summary> /// Checks if role is in collection by RoleID /// </summary> /// <param name="adaptorUserUserRoles"></param> /// <param name="role"></param> /// <returns></returns> private static bool IsRoleInCollection(IEnumerable <AdaptorUserUserRole> adaptorUserUserRoles, UserRoleType role) { return(adaptorUserUserRoles.Any(x => x.AdaptorUserRoleId.Equals((long)role))); }
public AuthPolicyRequirement(UserRoleType type) { this.UserRoleType = type; }
/// <summary> /// Checks and adds Role to collection when is not in collection grouped by User /// </summary> /// <param name="currentUserUserRoles">Collection of role to user mapping grouped by User</param> /// <param name="roleType"></param> /// <param name="adaptorUserUserRolesCollection">Global role to user collection mapping</param> private static void CheckAndAddUserUserRole(IEnumerable <AdaptorUserUserRole> currentUserUserRoles, UserRoleType roleType, List <AdaptorUserUserRole> adaptorUserUserRolesCollection) { var userRole = currentUserUserRoles.FirstOrDefault(); if (!IsRoleInCollection(currentUserUserRoles, roleType)) { adaptorUserUserRolesCollection.Add(new AdaptorUserUserRole() { AdaptorUserId = userRole.AdaptorUserId, AdaptorUserRoleId = (long)roleType }); } }
public AuthorizationAttribute(UserRoleType roleType, string result = "") { RoleCodes = new int[] { (int)roleType }; Result = result; }
public Task AssociateAdvisorUserRoleAsync(string NTLogin, UserRoleType AdvisorRole, string ModifiedBy) { throw new NotImplementedException(); }
public bool IsInRole(UserRoleType role) { return UserRoles.Any(r => r.RoleType == role); }
public async Task <IActionResult> GetByRole(UserRoleType role) { var response = await _mediator.Send(new ClientQueryRequest(role : role)); return(CustomResponse.GetResponse(response)); }
public UserRoleModel(UserRoleType name, params UserOperationModel[] userOperations) { this.Name = name; this.UserOperations = userOperations; }
public UserRoleViewModel(UserRoleType userRoleType) { UserRoleType = userRoleType; }