コード例 #1
0
        public static void LogAction(string controller, string action, bool success, string errorMessage)
        {
            var factory = ServiceLocator.Current.GetInstance <ISessionFactory>();

            using (var manager = new MiniSessionService(factory))
            {
                manager.OpenSessionWithTransaction();

                var repo = ServiceLocator.Current
                           .GetInstance <Data.DAL.IRepositoryBuilder>()
                           .CreateCreateRepository(manager);
                // If Logging is disabled, return
                var logSetting = repo.Get <ApplicationSetting>(s => s.Key == "OperationAccessLog").FirstOrDefault();
                if (
                    logSetting == null ||
                    string.IsNullOrWhiteSpace(logSetting.Value) ||
                    string.Compare(logSetting.Value, "false", StringComparison.OrdinalIgnoreCase) == 0 ||
                    string.Compare(logSetting.Value, "0", StringComparison.OrdinalIgnoreCase) == 0
                    )
                {
                    return;
                }
                ApplicationUser user = null;
                var             activePermissions = new List <string>();
                try
                {
                    user = GetCurrentApplicationUser();
                    activePermissions = GetCurrentApplicationUserPermissions();
                }
                catch (Exception e)
                {
                    var log = LogManager.GetLogger(typeof(IdentityHelper));
                    log.Error($"Failed to GetCurrentApplicationUser while Logging action: {controller}.{action}", e);
                }
                var entry = new ApplicationUserAction
                {
                    UserName          = user == null ? "Anonymous" : user.UserName,
                    Action            = action,
                    Controller        = controller,
                    Date              = DateTime.UtcNow,
                    ActivePermissions = user == null ? "" : string.Join(";", activePermissions),
                    ActiveRoles       = user == null ? "" : string.Join(";", user.Roles.Select(x => x.Name)),
                    Success           = success,
                    ErrorMessage      = errorMessage
                };
                repo.Save(entry);

                manager.CommitChanges();
            }
        }
 public IAuditingRepository CreateAuditingRepository(MiniSessionService manager) => throw new NotImplementedException();
 public IRetrieveRepository CreateRetrieveRepository(MiniSessionService manager = null) => new Repository(manager);
 public IIdentityRepository CreateIdentityRepository(MiniSessionService manager = null) => new Repository(manager);
 public IDeleteRepository CreateDeleteRepository(MiniSessionService manager = null) => new Repository(manager);
 public IWorkflowRepository CreateWorkflowRepository(MiniSessionService manager = null)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 public IIdentityRepository CreateIdentityRepository(MiniSessionService sessionManager = null)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 public IRetrieveRepository CreateRetrieveRepository(MiniSessionService manager = null)
 {
     return(CreateCreateRepository((IMiniSessionService)manager));
 }
コード例 #9
0
 public IDeleteRepository CreateDeleteRepository(MiniSessionService manager = null)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public IIdentityRepository CreateIdentityRepository(MiniSessionService sessionManager)
 {
     return(null);
 }
コード例 #11
0
 public IDeleteRepository CreateDeleteRepository(MiniSessionService manager)
 {
     return(null);
 }
コード例 #12
0
 public IWorkflowRepository CreateWorkflowRepository(MiniSessionService manager)
 {
     return(null);
 }
コード例 #13
0
 public IRetrieveRepository CreateRetrieveRepository(MiniSessionService manager)
 {
     return(null);
 }