/// <summary> /// Save a Section /// </summary> /// <param name="dc"></param> /// <param name="section"></param> /// <returns>returns the id of the saved section</returns> public int Save(DataContext dc, Domain.Section section) { dc = dc ?? Conn.GetContext(); var dbSection = dc.Sections.Where(s => s.SectionID == section.ID).SingleOrDefault(); var isNew = false; if (dbSection == null) { dbSection = new DataAccess.SqlRepository.Section(); isNew = true; } dbSection.Name = section.Name; dbSection.GreenhouseID = section.GreenhouseID; dbSection.PresetID = section.PresetID; dbSection.UserID = section.UserID; dbSection.IsTemperatureActivated = section.IsTemperatureActivated; dbSection.IdealTemperature = section.IdealTemperature; dbSection.TemperatureThreshold = section.TemperatureThreshold; dbSection.IsLightActivated = section.IsLightActivated; dbSection.IdealLightIntensity = section.IdealLightIntensity; dbSection.LightIntensityThreshold = section.LightIntensityThreshold; dbSection.IsHumidityActivated = section.IsHumidityActivated; dbSection.IdealHumidity = section.IdealHumidity; dbSection.HumidityThreshold = section.HumidityThreshold; dbSection.IsWaterLevelActivated = section.IsWaterLevelActivated; dbSection.IdealWaterLevel = section.IdealWaterLevel; dbSection.WaterLevelThreshold = section.WaterLevelThreshold; dbSection.DateUpdated = DateTime.Now; if (isNew) { dbSection.DateCreated = DateTime.Now; dc.Sections.InsertOnSubmit(dbSection); } dc.SubmitChanges(); return(dbSection.SectionID); }
/// <summary> /// Save a Section /// </summary> /// <param name="dc"></param> /// <param name="section"></param> /// <returns>returns the id of the saved section</returns> public int Save(DataContext dc, Domain.Section section) { dc = dc ?? Conn.GetContext(); var dbSection = dc.Sections.Where(s => s.SectionID == section.ID).SingleOrDefault(); var isNew = false; if (dbSection == null) { dbSection = new DataAccess.SqlRepository.Section(); isNew = true; } dbSection.Name = section.Name; dbSection.GreenhouseID = section.GreenhouseID; dbSection.PresetID = section.PresetID; dbSection.UserID = section.UserID; dbSection.IsTemeratureActivated = section.IsTemperatureActivated; dbSection.IdealTemperature = section.IdealTemperature; dbSection.TemperatureThreshold = section.TemperatureThreshold; dbSection.IsLightActivated = section.IsLightActivated; dbSection.IdealLightIntensity = section.IdealLightIntensity; dbSection.LightIntensityThreshold = section.LightIntensityThreshold; dbSection.IsHumidityActivated = section.IsHumidityActivated; dbSection.IdealHumidity = section.IdealHumidity; dbSection.HumidityThreshold = section.HumidityThreshold; dbSection.IsWaterLevelActivated = section.IsWaterLevelActivated; dbSection.IdealWaterLevel = section.IdealWaterLevel; dbSection.WaterLevelThreshold = section.WaterLevelThreshold; dbSection.DateUpdated = DateTime.Now; if (isNew) { dbSection.DateCreated = DateTime.Now; dc.Sections.InsertOnSubmit(dbSection); } dc.SubmitChanges(); return dbSection.SectionID; }