public static void GenerateRandomRecords(DateTime from, DateTime to) { var allConfigurations = DbConfigurationManager.GetConfigurations(null); var daily = allConfigurations.Where(c => c.PeriodicityId == 1).ToList(); var monthly = allConfigurations.Where(c => c.PeriodicityId == 2).ToList(); var randGen = new RandomGenerator(); using (var ctx = new Entities()) { var currDay = from; while (currDay <= to) { ctx.Records.AddRange( CreateRecords(currDay, monthly, randGen)); currDay = currDay.AddMonths(1); } currDay = from; while (currDay <= to) { ctx.Records.AddRange( CreateRecords(currDay, daily, randGen)); currDay = currDay.AddDays(1); } ctx.SaveChanges(); } }
public static void ResetDatabaseData() { using (var ctx = new Entities()) { ctx.ResetDatabaseData(); ctx.SaveChanges(); } }
public static void DeleteConfiguration(int id) { using (var ctx = new Entities()) { ctx.Entry<Configuration>(new Configuration() {Id = id}) .State = EntityState.Deleted; ctx.SaveChanges(); } }
public static Configuration CreateConfiguration(Configuration configuration) { configuration.User = null; configuration.EnergyType = null; configuration.Periodicity = null; using (var ctx = new Entities()) { ctx.Configurations.Add(configuration); ctx.SaveChanges(); return configuration; } }
public static void UpdateConfiguration(Configuration configuration) { using (var ctx = new Entities()) { var conf = ctx.Configurations .Single(c => c.Id == configuration.Id); conf.EnergyTypeId = configuration.EnergyTypeId; conf.PeriodicityId = configuration.PeriodicityId; conf.Name = configuration.Name; conf.Order = configuration.Order; ctx.SaveChanges(); } }