public static bool Save(Performance performance)
        {
            DbContextTransaction transaction = null;

            try
            {
                using (var _db = new MonitoringContext())
                {
                    using (transaction = _db.Database.BeginTransaction())
                    {
                        _db.Performances.Add(performance);
                        //_db.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[Performance] ON");
                        _db.SaveChanges();
                        // _db.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[Performance] OFF");
                        transaction.Commit();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                AuditLogRepository.Save(ex);
            }


            return(false);
        }
        public static IList <Performance> GetAll()
        {
            try
            {
                using (var _db = new MonitoringContext())
                {
                    using (var transaction = _db.Database.BeginTransaction())
                    {
                        return(_db.Performances.ToList());
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }

            return(null);
        }
        public static bool DeleteAll()
        {
            try
            {
                using (var _db = new MonitoringContext())
                {
                    _db.Database.ExecuteSqlCommand("TRUNCATE TABLE [AuditLog]");

                    return(true);
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                Save(ex);
            }

            return(false);
        }
        public static IList <AuditLog> RetrieveAll()
        {
            DbContextTransaction transaction = null;

            try
            {
                using (var _db = new MonitoringContext())
                {
                    using (transaction = _db.Database.BeginTransaction())
                    {
                        return(_db.AuditLogs.ToList());
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                Save(ex);
            }

            return(null);
        }
        public static bool Save(Exception exception)
        {
            DbContextTransaction transaction = null;

            try
            {
                using (var _db = new MonitoringContext())
                {
                    using (transaction = _db.Database.BeginTransaction())
                    {
                        //this should be in the AuditLog class, but as this project is going EF database first, that class is generated
                        var auditLog = new AuditLog
                        {
                            Exception      = exception.Message,
                            InnerException = exception.InnerException?.InnerException?.Message,
                            Source         = exception.Source,
                            StackTrace     = exception.StackTrace,
                            TargetSite     = exception.TargetSite.Name,
                            ExceptionDate  = DateTime.Now
                        };

                        _db.AuditLogs.Add(auditLog);
                        //_db.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[AuditLog] ON");
                        _db.SaveChanges();
                        // _db.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[AuditLog] OFF");
                        transaction.Commit();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }

            return(false);
        }