public static void AddUserToRole(Guid UserId, string roleName) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name.ToLower() == roleName.ToLower() select r).FirstOrDefault(); membership_User user = (from u in _db.membership_Users join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey where ud.UserId == UserId select u).FirstOrDefault(); membership_UserRole usrRole = (from r in _db.membership_Roles join ur in _db.membership_UserRoles on r.Id equals ur.RoleId join u in _db.membership_Users on ur.UserId equals u.Id join ud in _db.carrot_UserDatas on u.Id equals ud.UserKey where r.Name.ToLower() == roleName.ToLower() && ud.UserId == UserId select ur).FirstOrDefault(); if (usrRole == null && role != null && user != null) { usrRole = new membership_UserRole(); usrRole.UserId = user.Id; usrRole.RoleId = role.Id; _db.membership_UserRoles.InsertOnSubmit(usrRole); _db.SubmitChanges(); } } }
internal UserRole(membership_Role role) { if (role != null) { this.RoleId = role.Id; this.RoleName = role.Name; } }
public static bool AddUserToRole(string userName, string roleName) { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name == roleName select r).FirstOrDefault(); membership_User user = (from u in _db.membership_Users where u.UserName == userName select u).FirstOrDefault(); membership_UserRole usrRole = (from r in _db.membership_Roles join ur in _db.membership_UserRoles on r.Id equals ur.RoleId join u in _db.membership_Users on ur.UserId equals u.Id where r.Name == roleName && u.UserName == userName select ur).FirstOrDefault(); if (usrRole == null && role != null && user != null) { usrRole = new membership_UserRole(); usrRole.UserId = user.Id; usrRole.RoleId = role.Id; _db.membership_UserRoles.InsertOnSubmit(usrRole); _db.SubmitChanges(); return(true); } return(false); } }
internal UserRole(membership_Role role) { if (role != null) { this.RoleId = role.Id; this.RoleName = role.Name; } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name.ToLower() == this.RoleName.ToLower() || r.Id == this.RoleId select r).FirstOrDefault(); if (role == null) { role = new membership_Role(); role.Id = Guid.NewGuid().ToString().ToLower(); _db.membership_Roles.InsertOnSubmit(role); } role.Name = this.RoleName.Trim(); _db.SubmitChanges(); this.RoleName = role.Name; this.RoleId = role.Id; } }
public void Save() { using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { membership_Role role = (from r in _db.membership_Roles where r.Name == this.RoleName || r.Id == this.RoleId select r).FirstOrDefault(); if (role == null) { role = new membership_Role(); role.Id = Guid.NewGuid().ToString().ToLowerInvariant(); _db.membership_Roles.InsertOnSubmit(role); } role.Name = this.RoleName.Trim(); _db.SubmitChanges(); this.RoleName = role.Name; this.RoleId = role.Id; } }