public string AddRole(RoleTable roleDetails) { string res = ""; try { using (TechLeagueDBEntities objEntity = new TechLeagueDBEntities()) { objEntity.RoleTables.Add(roleDetails); int result = objEntity.SaveChanges(); if (result > 0) { res = "Success"; } else { res = "Failed"; } } } catch (Exception ex) { res = ex.ToString(); } return(res); }
public static void ClassInitialize(TestContext context) { _database = new Database(IdentityConstants.ConnecionName); _roleTable = new RoleTable(_database); _userTable = new UserTable <IdentityUser>(_database); _userRoleTable = new UserRoleTable(_database); _userTable.Insert(new IdentityUser() { UserName = name1, Email = email1 }); _userTable.Insert(new IdentityUser() { UserName = name2, Email = email2 }); _roleTable.Insert(new IdentityRole() { Name = role1 }); _roleTable.Insert(new IdentityRole() { Name = role2 }); }
public void Initialize() { database = new DbManager("DefaultConnection"); userRoleTable = database.GetUserRoleTable(); userTable = database.GetUserTable <IdentityUser>(); roleTable = database.GetRoleTable(); }
public override bool IsUserInRole(string callSign, string roleName) { bool outputResult = false; using (TaxiDBEntities db = new TaxiDBEntities()) { try { Employees user = db.Employees.FirstOrDefault(u => u.CallSign == callSign); if (user != null) { RoleTable userRole = db.RoleTable.Find(user.IdRole); if (userRole != null && userRole.Name == roleName) { outputResult = true; } } } catch { outputResult = false; } } return(outputResult); }
protected void btnSaveRole_Click(object sender, EventArgs e) { RoleRepository rl = new RoleRepository(); RoleTable l = new RoleTable(); l.RoleName = txtName.Text; rl.AddRole(l); }
protected void btnSubmit_Click(object sender, EventArgs e) { SnitzRoleProvider.UpdateRoleInfo(Convert.ToInt32(txtRoleID.Text), txtName.Text, txtDescription.Text); RoleTable.DataBind(); RoleView.SetActiveView(viewNewRole); errLbl2.Visible = false; }
public RoleTable GetRoleTable() { if (roleTable == null) { roleTable = new RoleTable(connStringName); } return(roleTable); }
public UserStore(IDbConnectionFactory dbConnectionFactory) { DbConnectionFactory = dbConnectionFactory; UserTable = new UserTable <TUser>(dbConnectionFactory); RoleTable = new RoleTable(dbConnectionFactory); UserRolesTable = new UserRolesTable(dbConnectionFactory); UserClaimsTable = new UserClaimsTable(dbConnectionFactory); UserLoginsTable = new UserLoginsTable(dbConnectionFactory); }
public Task CreateAsync(TRole role) { if (role == null) { throw new ArgumentNullException(nameof(role)); } return(RoleTable.Insert(role)); }
public Task DeleteAsync(TRole role) { if (role == null) { throw new ArgumentNullException(nameof(role)); } return(RoleTable.Delete(role.Id)); }
public ActionResult Succeed(RoleTable po) { PermissionEntities perEntities = new PermissionEntities(); perEntities.RoleTable.Add(po); perEntities.SaveChanges(); return(Redirect("/Role_Zhang_/List")); //return View(); }
public ActionResult Delete(RoleTable po) { PermissionEntities perEntities = new PermissionEntities(); System.Data.Entity.Infrastructure.DbEntityEntry entityEntry = perEntities.Entry(po); entityEntry.State = System.Data.Entity.EntityState.Deleted; perEntities.SaveChanges(); return(Redirect("/Role_Zhang_/List")); }
public ActionResult Register() { //var rs = new RoleStore<IdentityRole>(); //var roles = rs.Roles.AsEnumerable(); RoleTable rt = new RoleTable(new DbManager("")); var roles = rt.GetAllRoles(); ViewBag.Roles = new SelectList(roles, "Id", "Name"); return(View()); }
/// <summary> /// Constructor that takes a dbmanager as argument /// </summary> /// <param name="database"></param> public UserStore(DbManager database) { Database = database; userTable = database.GetUserTable <TUser>(); roleTable = database.GetRoleTable(); userRolesTable = database.GetUserRoleTable(); userClaimsTable = database.GetUserClaimTable(); userLoginsTable = database.GetUserLoginTable(); }
public UserStore(SqlServerDatabase database) { Database = database; _userTable = new UserTable <T>(database); _userLoginsTable = new UserLoginsTable <T>(database); _roleTable = new RoleTable <ApplicationRole>(database); _userRolesTable = new UserRolesTable <T>(database); _userClaimsTable = new UserClaimsTable(database); }
public UserStore(Database nPocoDb) { NPocoDb = nPocoDb; _userTable = new UserTable <TUser>(nPocoDb); _roleTable = new RoleTable(nPocoDb); _claimTable = new ClaimTable(nPocoDb); _clientTable = new ClientTable(nPocoDb); _userRoleTable = new UserRoleTable(nPocoDb); _userClaimTable = new UserClaimTable(nPocoDb); _userLoginTable = new UserLoginTable(nPocoDb); }
public override void CreateRole(string roleName) { RoleTable newRole = new RoleTable() { Name = roleName }; TaxiDBEntities db = new TaxiDBEntities(); db.RoleTable.Add(newRole); db.SaveChanges(); }
public async Task AddToRoleAsync(TUser user, string roleName) { if (user == null) { throw new ArgumentNullException(nameof(user)); } IRole <int> role = await RoleTable.GetRoleByName(roleName); if (role != null) { await UserRolesTable.Insert(user, role.Id); } }
public void TestRoleUpdate() { Role role = RoleTable.Insert(this.connection, "test"); Assert.AreEqual("test", role.Name); role.Name = "test2"; Assert.IsTrue(RoleTable.Update(this.connection, role)); role = RoleTable.GetRoleById(this.connection, role.Id); Assert.AreEqual("test2", role.Name); Assert.IsTrue(RoleTable.Delete(this.connection, role)); }
public void Dispose() { if (NPocoDb != null) { NPocoDb.Dispose(); NPocoDb = null; } _userTable = null; _roleTable = null; _claimTable = null; _clientTable = null; _userRoleTable = null; _userClaimTable = null; _userLoginTable = null; }
public void TestRoleCreation() { Role role = RoleTable.Insert(this.connection, "test"); Role other = RoleTable.GetRoleById(this.connection, role.Id); Assert.AreEqual(role.Name, other.Name, "Jména rolí se neshodují"); Assert.IsTrue(RoleTable.Delete(this.connection, role)); try { RoleTable.GetRoleById(this.connection, role.Id); Assert.Fail("Role pořád existuje"); } catch (DatabaseException) { } }
public ActionResult Updata(RoleTable po) { if (po.Name != "") { //声明数据库上下文类 PermissionEntities perEntities = new PermissionEntities(); System.Data.Entity.Infrastructure.DbEntityEntry entityEntry = perEntities.Entry(po); entityEntry.State = System.Data.Entity.EntityState.Modified; perEntities.SaveChanges(); } else { return(Content("名称为空")); } return(Redirect("/Role_Zhang_/List")); }
public void TestUserUpdate() { User user = UserTable.Insert(this.connection, 1, "John", "Tester"); user.Name = "Jack"; user.Surname = "Trader"; user.Role = RoleTable.GetRoleById(this.connection, 2); Assert.IsTrue(UserTable.Update(this.connection, user)); User changedUser = UserTable.GetUserById(this.connection, user.Id); Assert.AreEqual(user.Name, changedUser.Name); Assert.AreEqual(user.Surname, changedUser.Surname); Assert.AreEqual(user.Role.Id, changedUser.Role.Id); Assert.IsTrue(UserTable.Delete(this.connection, changedUser)); }
public UnitOfWork() { _database = new Entities(); User = new UserTables(_database.Users); SecurityQuestion = new SecurityQuestionTables(_database.SecurityQuestions); Role = new RoleTable(_database.Roles); OrganisationTable = new OrganisationTable(_database.OrganisationDetails); BranchTable = new BranchTable(_database.BrancheDetails); BankTable = new BankTable(_database.BankDetails); EmployeeTable = new EmployeeTable(_database.Employees); EmployeeLocationTable = new EmployeeLocationTable(_database.EmployeeLocations); CustomerTable = new CustomerTable(_database.Customers); AccountTable = new AccountTable(_database.Accounts); AccountTypeTable = new AccountTypeTable(_database.AccountTypes); AccessLevelTable = new AccountAccessLevelTable(_database.AccessLevels); UserAccountAccessTable = new UserAccountAccessTable(_database.UserAccountAccesses); AccoutTransactionTable = new AccoutTransactionTable(_database.Transactions); }
public static void ClassInitialize(TestContext context) { _database = new Database(IdentityConstants.ConnectionName); _roleTable = new RoleTable(_database); _userTable = new UserTable <IdentityUser>(_database); _userLoginTable = new UserLoginTable(_database); _clientTable = new ClientTable(_database); _clientTable.Insert(new IdentityClient(client)); TestClientId = _clientTable.GetClientByName(client).Id; _userTable.Insert(new IdentityUser(TestClientId, name1) { Email = email1 }); _userTable.Insert(new IdentityUser(TestClientId, name2) { Email = email2 }); }
public async Task <SelectList> RetrieveRoles() { ApplicationDbContext context = ApplicationDbContext.Create(); var roletable = new RoleTable(context); var roleList = new List <SelectListItem>(); var retrievedRoles = await Task.Run( () => roletable.GetRoles(). Select(r => new { r.Id, r.Name }). Where(r => r.Name.ToUpper() != "patient".ToUpper())); foreach (var role in retrievedRoles) { var roleItem = new SelectListItem { Value = role.Id.ToString(), Text = role.Name }; roleList.Add(roleItem); } return(new SelectList(roleList, "Value", "Text", 16)); }
public IActionResult Add([FromBody] RoleTable role) { try { int id = _repository.SaveGetId(role); return(Json(new { id, state = "0", msg = "添加成功!" })); } catch (Exception ex) { return(Json(new { state = "-1", msg = "非法操作!" })); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteClick") { try { if (Roles.DeleteRole(e.CommandArgument.ToString(), !delPopRoles.Checked)) { errLbl2.Text = "Role deleted successfully."; errLbl2.Visible = true; } } catch (ProviderException p) { errLbl2.Text = p.Message; errLbl2.Visible = true; } RoleTable.DataBind(); } if (e.CommandName == "EditClick") { SnitzRoleProvider srp = new SnitzRoleProvider(); int roleid = Convert.ToInt32(e.CommandArgument); RoleInfo role = SnitzRoleProvider.GetRoleFull(roleid); txtRoleID.Text = roleid.ToString(); txtName.Text = role.RoleName; txtDescription.Text = role.Description.ToString(); UsersInRole.Text = String.Format("{0} User(s) in {1} Role", srp.GetUsersInRole(txtName.Text).Length, role.RoleName); RoleView.SetActiveView(viewEditRole); errLbl2.Visible = false; UserListPanel.Visible = (roleid > 1); RefreshUserList(); } }
public override string[] GetRolesForUser(string CallSign) { string[] role = new string[] { }; using (TaxiDBEntities db = new TaxiDBEntities()) { try { Employees user = db.Employees.FirstOrDefault(u => u.CallSign == CallSign); if (user != null) { RoleTable userRole = db.RoleTable.Find(user.IdRole); if (userRole != null) { role = new[] { userRole.Name }; } } } catch { role = new string[] { }; } } return(role); }
/// <summary> /// Constructor that takes a dbmanager as argument /// </summary> /// <param name="database"></param> public RoleStore(DbManager database) { Database = database; roleTable = database.GetRoleTable(); }