public static FUTMuleApiStatistic GetInstance() { lock (_statisticLock) { using (var ctx = new FUTLogsDatabase()) { var statistic = ctx.FUTMuleApiStatistics.FirstOrDefault(); if (statistic == null) { var ret = new FUTMuleApiStatistic(); ret.Reset(); ctx.FUTMuleApiStatistics.Add(ret); ctx.SaveChanges(); return(ret); } return(statistic); } } }
public void SaveChanges() { lock (_statisticLock) { using (var context = new FUTLogsDatabase()) { var statistic = context.FUTMuleApiStatistics.FirstOrDefault(); if (statistic == null) { statistic = new FUTMuleApiStatistic(); statistic.Reset(); context.FUTMuleApiStatistics.Add(statistic); context.SaveChanges(); } else { context.Entry(statistic).CurrentValues.SetValues(this); context.SaveChanges(); } } } }