public static MvcHtmlString AddButton(this HtmlHelper html, string function, string text, ApplicationRoles role) { var result = string.Empty; if (!HttpContext.Current.User.IsInRole(role.ToString())) { return(new MvcHtmlString(result)); } result = $"<a onclick=\"{function}\" class=\"btn btn-sm btn-default\">" + $"<i class=\"glyphicon glyphicon-plus\"></i> Add {text}</a>"; return(new MvcHtmlString(result)); }
public async Task <OperationStatus> ChangeUserRoleAsync(string userId, ApplicationRoles role) { var roles = await _identityUserManagerService.GetRolesAsync(userId); if (roles.Count > 0) { var identityResult = await _identityUserManagerService.RemoveFromRolesAsync(userId, roles.ToArray()); if (!identityResult.Succeeded) { return(new FailureStatus(identityResult.Errors.FirstOrDefault())); } } if (role != ApplicationRoles.None) { var identityResult = await _identityUserManagerService.AddToRoleAsync(userId, role.ToString()); if (!identityResult.Succeeded) { return(new FailureStatus(identityResult.Errors.FirstOrDefault())); } } return(new SuccessStatus()); }