Ejemplo n.º 1
0
        public static void AddException(Exception exception, string comments = null, LogExceptionLevel level = LogExceptionLevel.Low)
        {
            if (exception == null)
                return;

            try
            {
                var baseException = exception.GetBaseException();
                using (var db = new DbEntities())
                {
                    db.InsertException(new LogException()
                    {
                        Comments = comments,
                        ExceptionLevel = (short)level,
                        InsertionTime = DateTime.Now,
                        Message = exception.Message,
                        InnerException = (exception.InnerException != null) ? exception.InnerException.Message : null,
                        StackTrace = exception.StackTrace,
                        TargetSite = (exception.TargetSite != null) ? exception.TargetSite.Name : null,
                        Source = exception.Source,
                        BaseException = (baseException != null) ? baseException.Message : null
                    });
                }
            }
            catch { }
        }
Ejemplo n.º 2
0
            private static bool IsAuthorize()
            {
                try
                {
                    if (!Current.User.Identity.IsAuthenticated)
                        return false;

                    if (User == null)
                    {
                        int id;
                        if (!Int32.TryParse(Current.User.Identity.Name, out id))
                            return false;

                        using (var db = new DbEntities())
                        {
                            var user = db.Usuarios
                                         .Include(u => u.Roles).Include(u => u.Roles.Permisos)
                                         .FirstOrDefault(u => u.USUID == id);

                            if (user == null || !user.USUActivo || user.Roles == null || user.Roles.Permisos == null || user.Roles.Permisos.Count == 0)
                                return false;

                            User = user.CastToDTOCurrentUser();
                        }
                    }

                    var rvd = Current.Request.RequestContext.RouteData.Values;
                    string objectId = string.Format("{0}/{1}", rvd["controller"], rvd["action"]);

                    return User.Permisos.Any(p => p.PERObjeto == objectId && p.PERActivo);
                }
                catch (Exception exc)
                {
                    Utils.AddException(exc, level: LogExceptionLevel.High);
                }

                return false;
            }