public override void CreateRole(string roleName) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { db.ROLES.Add(new ROLES { Nombre = roleName, Activo = true }); db.SaveChanges(); } }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { if (!Roles.Provider.RoleExists("Admin")) { Roles.CreateRole("Admin"); } if (!Roles.Provider.RoleExists("Cajero")) { Roles.CreateRole("Cajero"); } foreach (var user in usernames) { foreach (var rol in roleNames) { db.USUARIOROLES.Add(new USUARIOROLES { UserId = db.USUARIO.SingleOrDefault(x => x.NombreUsuario.Equals(user, StringComparison.CurrentCultureIgnoreCase)).Id, RolId = db.ROLES.SingleOrDefault(x => x.Nombre.Equals(rol, StringComparison.CurrentCultureIgnoreCase)).Id, Activo = true }); db.SaveChanges(); } } } }