public void LoadEmployees() { Worksheet sheet = workBook.Worksheets[0]; int rowIndex = 1; int colIndex = 3; employees.Clear(); List <string> Roles = new List <string>(); rolesDict.Clear(); while (sheet.Cells.GetRow(rowIndex).GetCell(colIndex).StringValue != "") { Employee emp = new Employee(); emp.EID = sheet.Cells.GetRow(rowIndex).GetCell(colIndex).StringValue.Trim(); emp.FirstName = new CultureInfo("en-US").TextInfo.ToTitleCase(sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 2).StringValue.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1].Trim().ToLower()); emp.LastName = new CultureInfo("en-US").TextInfo.ToTitleCase(sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 2).StringValue.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[0].Trim().ToLower()); emp.FullNameUk = new CultureInfo("en-US").TextInfo.ToTitleCase(sheet.Cells.GetRow(rowIndex).GetCell(colIndex - 2).StringValue.Trim()); string dateOfEmployment = sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 6).StringValue.Trim(new char[] { '\n' }); if (dateOfEmployment != "") { emp.DateEmployed = DateTime.FromOADate(Int32.Parse(dateOfEmployment)); } string dateOfBirth = sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 3).StringValue; if (dateOfBirth != "") { emp.BirthDay = DateTime.FromOADate(Int32.Parse(dateOfBirth)); } string dateOfDismissal = sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 9).StringValue; if (dateOfDismissal != "") { emp.DateDismissed = DateTime.FromOADate(Int32.Parse(dateOfDismissal)); } emp.Department = new Department { DepartmentName = (from d in departments where d.DepartmentName == sheet.Cells.GetRow(rowIndex).GetCell(colIndex - 1).StringValue.Trim() select d.DepartmentName).FirstOrDefault() }; emp.Position = new Position { TitleUk = (from p in positions where p.TitleUk == sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 7).StringValue.Trim() select p.TitleUk).FirstOrDefault() }; emp.IsManager = sheet.Cells.GetRow(rowIndex).GetCell(colIndex + 17).StringValue.Trim() != "" ? true : false; employees.Add(emp); for (int i = 10; i <= 16; i++) { string role = sheet.Cells.GetRow(rowIndex).GetCell(colIndex + i).StringValue.Trim(); if (role != "") { RolesEnum r = (RolesEnum)(i - 10); Roles.Add(r.ToString()); } } rolesDict.Add(emp.EID, Roles.ToArray <string>()); Roles.Clear(); rowIndex++; } }
public bool CheckRole(string token, RolesEnum role) { var rolesRepository = new RolesRepository(); var id = rolesRepository.FindByName(role.ToString()).Id; var decodedToken = Decode(token); var tokenId = int.Parse(decodedToken["role"].ToString()); return(id == tokenId); }
protected bool HasRole(RolesEnum role) { if (Request.Cookies.TryGetValue(IssuedTokenName, out string jwt)) { return(_tokenService.GetAllClaims(jwt) .Any(claim => claim.Type == "role" && claim.Value == role.ToString())); } return(false); }
/// <summary> /// Create new user account /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <param name="role"></param> /// <returns></returns> public async Task <UserResponseModel> SignUp(ApplicationUser user, string password, RolesEnum role) { var result = await _userManager.CreateAsync(user, password); if (!result.Succeeded) { throw new Exception(result.Errors.ToString()); } await _userManager.AddToRoleAsync(user, role.ToString()); return(new UserResponseModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Role = role }); }
/// <summary> /// Allows to register new user /// </summary> /// <param name="user">New User (Entity)</param> /// <param name="password">New User password</param> /// <param name="role">Role new user will have</param> /// <returns></returns> public async Task <UserBaseInfo> Register(User user, string password, RolesEnum role) { var created = await UserManager.CreateAsync(user, password); if (!created.Succeeded) { return(null); } var roleAdded = await UserManager.AddToRoleAsync(user, role.ToString()); if (!roleAdded.Succeeded) { await UserManager.DeleteAsync(user); return(null); } var baseUserInfo = await UsersService.GetUserBaseInfo(user.Id); return(baseUserInfo); }
public bool IsInRole(RolesEnum roleID) { return IsInRole(roleID.ToString()); }
public static bool IsRoles(this SystemUser user, RolesEnum role) { bool result = user != null && user.AspNetUser != null && user.AspNetUser.AspNetRoles.Any(x => x.Name == role.ToString()); return(result); }
public async Task <IdentityResult> AddToRolesAsync(string id, RolesEnum rolesEnum) { string[] roles = rolesEnum.ToString().Split(',').Select(r => r.Trim()).ToArray(); return(await this.AddToRolesAsync(id, roles)); }
public static string ToStr(RolesEnum role) => role.ToString();
/// <summary> /// Check if the user has the specified role. /// </summary> /// <param name="role"></param> /// <returns></returns> public bool IsInRole(RolesEnum role) { return(this.IsInRole(role.ToString())); }