public override bool RoleExists(string roleName) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { return(db.ROLES.ToList().Any(x => x.Nombre.Equals(roleName, StringComparison.CurrentCultureIgnoreCase))); } }
public override void CreateRole(string roleName) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { db.ROLES.Add(new ROLES { Nombre = roleName, Activo = true }); db.SaveChanges(); } }
public override bool IsUserInRole(string username, string roleName) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { USUARIO user = db.USUARIO.FirstOrDefault(u => u.NombreUsuario.Equals(username, StringComparison.CurrentCultureIgnoreCase)); var roles = from ur in user.USUARIOROLES from r in db.ROLES where ur.RolId == r.Id select r.Nombre; if (user != null) { return(roles.Any(r => r.Equals(roleName, StringComparison.CurrentCultureIgnoreCase))); } else { return(false); } } }
public Notificacion getNotificacion() { Notificacion result = new Notificacion(); using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { var ConsultaVentas = (from total in db.VENTA where total.FechaVenta.Equals(DateTime.Now.AddDays(-1)) select total.Total).ToList(); this.MontoVentasAyer = ConsultaVentas.Sum(x => x.Value); var ProductosMasVendidos = (from producto in db.PRODUCTO.DefaultIfEmpty() join listaventa in db.DETALLEVENTA.DefaultIfEmpty() on producto.Id equals listaventa.ProductoId group producto by new { producto.Id, producto } into gpr select gpr.Max(x => gpr.Count())); //var max =ProductosMasVendidos; //this.MenosVendido = ProductosMasVendidos.Min(x => x.Cantidad); } return(result); }
public override string[] GetRolesForUser(string username) { using (MyBoxSaleEntities db = new MyBoxSaleEntities()) { USUARIO user = db.USUARIO.FirstOrDefault(u => u.NombreUsuario.Equals(username, StringComparison.CurrentCultureIgnoreCase)); if (user != null) { var Roles = from ur in user.USUARIOROLES from r in db.ROLES where ur.RolId == r.Id select r.Nombre; if (Roles != null) { return(Roles.ToArray()); } else { return new string[] { } }; } return(new string[] { }); } }
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(); } } } }