public void AddOrUpdate(MOE.Common.Models.MetricComment metricComment) { MOE.Common.Models.MetricComment g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g != null) { try { db.Entry(g).CurrentValues.SetValues(metricComment); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.MetricCommentRepository"; error.Function = "AddOrUpdate"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { db.MetricComments.Add(metricComment); } }
public void AddOrUpdate(MOE.Common.Models.DetectorComment detectorComment) { MOE.Common.Models.DetectorComment g = (from r in db.DetectorComments where r.CommentID == detectorComment.CommentID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(detectorComment); } else { db.DetectorComments.Add(detectorComment); } try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public void AddOrUpdate(MOE.Common.Models.Approach approach) { MOE.Common.Models.Approach g = (from r in db.Approaches where r.ApproachID == approach.ApproachID select r).FirstOrDefault(); if (g != null) { try { db.Entry(g).CurrentValues.SetValues(approach); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "Update"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { try { foreach (Detector d in approach.Detectors) { if (d.DetectionTypes == null && d.DetectionTypeIDs != null) { d.DetectionTypes = db.DetectionTypes.Where(dt => d.DetectionTypeIDs.Contains(dt.DetectionTypeID)).ToList(); } } db.Approaches.Add(approach); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "Add"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public void Update(Models.ActionLog entity) { var agencyInDatabase = db.Agencies.Find(entity.ActionLogID); if (agencyInDatabase == null) { Add(entity); } else { db.Entry(agencyInDatabase).CurrentValues.SetValues(entity); } }
public void Update(Models.FAQ item) { FAQ faqFromDatabase = GetbyID(item.FAQID); if (faqFromDatabase != null) { db.Entry(faqFromDatabase).CurrentValues.SetValues(item); db.SaveChanges(); } else { throw new Exception("FAQ Not Found"); } }
public void Update(Models.Menu menuItem) { Menu menuFromDatabase = GetMenuItembyID(menuItem.MenuId); if (menuFromDatabase != null) { db.Entry(menuFromDatabase).CurrentValues.SetValues(menuItem); db.SaveChanges(); } else { throw new Exception("Menu Not Found"); } }
public void Update(MOE.Common.Models.MovementType movementType) { MOE.Common.Models.MovementType g = (from r in db.MovementTypes where r.MovementTypeID == movementType.MovementTypeID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(movementType); db.SaveChanges(); } else { db.MovementTypes.Add(movementType); db.SaveChanges(); } }
public void Update(MOE.Common.Models.Phase phase) { MOE.Common.Models.Phase g = (from r in db.Phases where r.PhaseID == phase.PhaseID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(phase); db.SaveChanges(); } else { db.Phases.Add(phase); db.SaveChanges(); } }
public void Update(MOE.Common.Models.SPMWatchDogErrorEvent SPMWatchDogErrorEvent) { MOE.Common.Models.SPMWatchDogErrorEvent g = (from r in db.SPMWatchDogErrorEvents where r.ID == SPMWatchDogErrorEvent.ID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(SPMWatchDogErrorEvent); db.SaveChanges(); } else { db.SPMWatchDogErrorEvents.Add(SPMWatchDogErrorEvent); db.SaveChanges(); } }
public void Update(MOE.Common.Models.DetectionHardware DetectionHardware) { MOE.Common.Models.DetectionHardware g = (from r in db.DetectionHardwares where r.ID == DetectionHardware.ID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(DetectionHardware); db.SaveChanges(); } else { db.DetectionHardwares.Add(DetectionHardware); db.SaveChanges(); } }
public void Update(MOE.Common.Models.DetectionType detectionType) { MOE.Common.Models.DetectionType g = (from r in db.DetectionTypes where r.DetectionTypeID == detectionType.DetectionTypeID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(detectionType); db.SaveChanges(); } else { db.DetectionTypes.Add(detectionType); db.SaveChanges(); } }
public void Update(MOE.Common.Models.Lane lane) { MOE.Common.Models.Lane g = (from r in db.Lanes where r.LaneID == lane.LaneID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(lane); db.SaveChanges(); } else { db.Lanes.Add(lane); db.SaveChanges(); } }
public void Update(MOE.Common.Models.ApplicationEvent applicationEvent) { MOE.Common.Models.ApplicationEvent g = (from r in db.ApplicationEvents where r.ID == applicationEvent.ID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(applicationEvent); db.SaveChanges(); } else { db.ApplicationEvents.Add(applicationEvent); db.SaveChanges(); } }
public void Update(MOE.Common.Models.Signal incomingSignal) { MOE.Common.Models.Signal signalFromDatabase = (from r in db.Signals where r.SignalID == incomingSignal.SignalID select r).FirstOrDefault(); if (signalFromDatabase != null) { db.Entry(signalFromDatabase).CurrentValues.SetValues(incomingSignal); if (incomingSignal.Approaches != null) { foreach (MOE.Common.Models.Approach a in incomingSignal.Approaches) { var approach = signalFromDatabase.Approaches.Where(app => app.ApproachID == a.ApproachID).FirstOrDefault(); if (approach != null) { if (!a.Equals(approach)) { db.Entry(approach).CurrentValues.SetValues(a); } } else { signalFromDatabase.Approaches.Add(a); } if (a.Detectors != null) { foreach (MOE.Common.Models.Detector newDetector in a.Detectors) { var detectorFromDatabase = signalFromDatabase.GetDetectorsForSignal().Where(d => d.ID == newDetector.ID).FirstOrDefault(); if (newDetector.DetectionTypes == null) { newDetector.DetectionTypes = db.DetectionTypes.Where(x => newDetector.DetectionTypeIDs.Contains(x.DetectionTypeID)).ToList(); } if (detectorFromDatabase != null) { if (!newDetector.Equals(detectorFromDatabase)) { if (detectorFromDatabase.DetectionTypes == null) { detectorFromDatabase.DetectionTypes = new List <DetectionType>(); } var deletedDetectionTypes = detectorFromDatabase.DetectionTypes .Except(newDetector.DetectionTypes).ToList <DetectionType>(); var addedDetectionTypes = newDetector.DetectionTypes .Except(detectorFromDatabase.DetectionTypes).ToList <DetectionType>(); deletedDetectionTypes.ForEach(delDet => detectorFromDatabase.DetectionTypes.Remove(delDet)); foreach (DetectionType n in addedDetectionTypes) { if (db.Entry(n).State == EntityState.Detached) { db.DetectionTypes.Attach(n); } detectorFromDatabase.DetectionTypes.Add(n); } //var detectionTypes = db.DetectionTypes.Where(x => gd.DetectionTypeIDs.Contains(x.DetectionTypeID)).ToList(); //graphDetector.DetectionTypes = detectionTypes; //graphDetector.DetectionTypeIDs = gd.DetectionTypeIDs; db.Entry(detectorFromDatabase).CurrentValues.SetValues(newDetector); } } else { if (newDetector.DetectionTypes == null) { newDetector.DetectionTypes = db.DetectionTypes.Where(x => newDetector.DetectionTypeIDs.Contains(x.DetectionTypeID)).ToList(); } approach.Detectors.Add(newDetector); } } } } } } else { foreach (Models.Approach a in incomingSignal.Approaches) { foreach (Models.Detector gd in a.Detectors) { gd.DetectionTypes = db.DetectionTypes.Where(x => gd.DetectionTypeIDs.Contains(x.DetectionTypeID)).ToList(); } } db.Signals.Add(incomingSignal); } try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public void Save(Models.WatchDogApplicationSettings watchDogApplicationSettings) { db.Entry(watchDogApplicationSettings).State = EntityState.Modified; db.SaveChanges(); }