public string GetRoleNameByRoleId(string roleId) { var role = AspNetSecurityHelper.FindRoleById(roleId); if (role != null) { return(role.Name); } else { return(null); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string operation = ""; string userId = e.CommandArgument.ToString(); if (!String.IsNullOrEmpty(userId)) { var user = AspNetSecurityHelper.FindUserById(userId); if (user != null) { if (e.CommandName == "ActiveUser") { if (user.LockoutEndDateUtc != null) { //user.Active = true; user.AccessFailedCount = 0; user.LockoutEndDateUtc = null; operation = (String)GetGlobalResourceObject("HCMResource", "Active"); } else { //user.Active = false; user.AccessFailedCount = 5; user.LockoutEndDateUtc = DateTime.Now.AddDays(365); operation = (String)GetGlobalResourceObject("HCMResource", "Lock"); } } else if (e.CommandName == "GrantPermission") { user.Active = true; var roles = user.Roles; if (roles.Count() == 0) { var role = AspNetSecurityHelper.FindRoleByName("Supervisor"); if (role != null) { AspNetSecurityHelper.InsertUserToRole(user.Id, role.Id); } } operation = (String)GetGlobalResourceObject("HCMResource", "GrantPermission"); } IdentityResult r = AspNetSecurityHelper.UpdateUser(user); if (r.Succeeded) { SSAManager _SSAManager = new SSAManager(); DAL.Entity.SaudiStudentAssociation obj = null; if (user != null) { if (user.UniversityId.HasValue) { obj = _SSAManager.GetSSAByUniversityId(user.UniversityId.Value); } //obj = _SSAManager.GetSSAByAdministratorId(user.Id); if (obj == null) { obj = new DAL.Entity.SaudiStudentAssociation(); } obj.AdministratorId = user.Id; if (user.UniversityId.HasValue && user.UniversityId.Value != 0) { obj.UniversityId = user.UniversityId.Value; } int i = 0; if (obj.Id == 0) { obj.CreatedBy = user.UserName; obj.CreatedDate = DateTime.Now; obj.DeletedFlag = false; i = _SSAManager.AddSSA(obj); } else { obj.LastUpdatedBy = user.UserName; obj.LastUpdatedDate = DateTime.Now; i = _SSAManager.UpdateSSA(obj); } } ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationSuccess"), operation), "", Common.msgType.alertMessageSuccess); } else { string errorStr = (String)GetGlobalResourceObject("HCMResource", "ActiveError"); foreach (string s in r.Errors) { errorStr += ", " + s.ToString(); } ucAlertMessage.AlertMessage(errorStr, "", Common.msgType.alertMessageDanger); } } else { ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), operation), "", Common.msgType.alertMessageDanger); } FillData(); } else { ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), operation), "", Common.msgType.alertMessageDanger); } }