public bool IsInRole(string role) { _SGCModel db = new _SGCModel(); /*var roles = role.Split(new char[] { ',' });//db.Formularios.ToList<Formularios>(); * return roles.Any(r => this.usuario.usuario_permisos.Contains(r));*/ int AccessId = db.permisos.Where(m => m.codigo_interno == role).Select(m => m.id).FirstOrDefault(); usuario_permisos userAccess = db.usuario_permisos.Where(m => m.usuario_id == usuarioId && m.permiso_id == AccessId && m.deleted_at == null).FirstOrDefault(); //usuario_permisos usuario_permiso = db.usuario_permisos.Where(up => up.usuarios.email == this.usuario.email && up.permiso_id == permiso_id).FirstOrDefault(); return(userAccess != null); }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static void ProcessQueueMessage([QueueTrigger("activeclientsvalidation")] string message, TextWriter logger) { using (_SGCModel db = new _SGCModel()) { foreach (clientes c in db.clientes.AsEnumerable()) { DateTime d = db.programa_clientes.Where(m => m.cliente_id == c.id_alt).OrderByDescending(m => m.fecha_inicio).Select(m => m.fecha_fin).FirstOrDefault(); if (d != null && d < DateTimeOffset.Now.Date) { c.activo = false; logger.WriteLine("Cliente código: " + c.codigo + ", ha cambiado su estado a Inactivo."); } } } }
public override void OnAuthorization(AuthorizationContext filterContext) { if (string.IsNullOrEmpty(SessionPersister.EmailUsuario)) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Login", ReturnUrl = filterContext.HttpContext.Request.RawUrl })); } else { _SGCModel db = new _SGCModel(); string mail = db.usuarios.Where(u => u.email.Equals(SessionPersister.EmailUsuario)).FirstOrDefault().email; int id = db.usuarios.Where(u => u.email.Equals(SessionPersister.EmailUsuario)).FirstOrDefault().id; CustomPrincipal mp = new CustomPrincipal(id, mail); if (!mp.IsInRole(SGC_AccessCode)) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Unauthorize" })); } } }