public static List <UserSecurityRole> GetSecurityRoles() { List <UserSecurityRole> Roles = new List <UserSecurityRole>(); using (SQLiteHelper SQLite = new SQLiteHelper()) { DataTable tblRoles = SQLite.Select("SELECT * FROM SecurityRole"); if (tblRoles.Rows.Count > 0) { foreach (DataRow row in tblRoles.Rows) { UserSecurityRole role = new UserSecurityRole(); int Id = 0; int.TryParse(row["Id"].ToString(), out Id); role.Id = Id; role.Name = row["Name"].ToString(); role.Status = row["Status"].ToString(); Roles.Add(role); } } } return(Roles); }
public UserSecurityRole UpdateUserSecurityRole(UserSecurityRole UserSecurityRole) { var c = ctx.UserSecurityRole.Where(x => x.ID == UserSecurityRole.ID).First(); if (c != null) { c.UserID = UserSecurityRole.UserID; c.SecurityRoleID = UserSecurityRole.SecurityRoleID; ctx.SaveChanges(); } return(c); }
protected void Application_PostAuthenticateRequest() { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); JavaScriptSerializer js = new JavaScriptSerializer(); UserSecurityRole user = js.Deserialize <UserSecurityRole>(ticket.UserData); SecurityIdentity identity = new SecurityIdentity(user); SecurityPrinciple principle = new SecurityPrinciple(identity); HttpContext.Current.User = principle; } }
public static bool AddSecurityRole(UserSecurityRole RoleEntry, List <UserSecurityRoleDetail> Details) { bool Result = false; using (SQLiteHelper SQLite = new SQLiteHelper()) { SQLite.Insert("SecurityRole", GetDictionary(RoleEntry, true)); RoleEntry.Id = (int)SQLite.LastInsertRowId(); foreach (UserSecurityRoleDetail item in Details) { item.RoleId = RoleEntry.Id; SQLite.Insert("SecurityRoleDetail", GetDictionary(item, true)); } } return(Result); }
public static bool UpdateSecurityRole(UserSecurityRole RoleEntry, List <UserSecurityRoleDetail> Details) { bool Result = false; using (SQLiteHelper SQLite = new SQLiteHelper()) { Dictionary <string, object> WhereClause = new Dictionary <string, object>(); WhereClause.Add("Id", RoleEntry.Id); SQLite.Update("SecurityRole", GetDictionary(RoleEntry, true), WhereClause); SQLite.Delete("SecurityRoleDetail", " RoleId = " + RoleEntry.Id); foreach (UserSecurityRoleDetail item in Details) { item.RoleId = RoleEntry.Id; SQLite.Insert("SecurityRoleDetail", GetDictionary(item, true)); } } return(Result); }
/// <summary> /// Create UserSecurityRole and at least one UserSecurityRole sign in. /// </summary> /// <param name="UserSecurityRole"></param> /// <returns></returns> public UserSecurityRole CreateUserSecurityRole(UserSecurityRole UserSecurityRole) { ctx.UserSecurityRole.Add(UserSecurityRole); ctx.SaveChanges(); return(UserSecurityRole); }