public ActionResult UserRoles(UserRolesViewModel model) { if (ModelState.IsValid) { var iws = new IWSHelper(); var Db = new ApplicationDbContext(); var user = Db.Users.First(u => u.UserName == model.UserName); foreach (var role in model.Roles) { if (role.Selected) { iws.AddUserToRole(user.UserName, role.RoleName); } else { iws.RemoveUserFromRole(user.UserName, role.RoleName); } } return(RedirectToAction("index")); } return(View()); }
public static SqlConnection getCurrentHandlerSqlConnection(string connectionStringKeyName) { if (HttpContext.Current.IsNull()) { return(null); } IWSHelper currentHandler = HttpContext.Current.Handler as IWSHelper; if (currentHandler.IsNull()) { currentHandler = HttpContext.Current.Items[WebServiceHelper.CURRENT_HANDLER_WS] as IWSHelper; } if (currentHandler.IsNull()) { return(null); } SqlConnection connection = currentHandler.getCurrentSqlConnection(connectionStringKeyName); if (connection.IsNull()) { return(null); } if (connection.IsNotReady()) { connection = new SqlConnection(connection.ConnectionString); currentHandler.addToConnectionList(connection); } if (connection.State != ConnectionState.Open) { connection.Open(); } return(connection); }