public void AddOrUpdate(MetricComment metricComment) { var 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) { var repository = ApplicationEventRepositoryFactory.Create(); var 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); db.SaveChanges(); } }
public void Update(RoutePhaseDirection newRoutePhaseDirection) { CheckForExistingApproach(newRoutePhaseDirection); var routePhaseDirection = db.RoutePhaseDirections.Where(r => r.Id == newRoutePhaseDirection.Id).FirstOrDefault(); if (routePhaseDirection != null) { try { db.Entry(routePhaseDirection).CurrentValues.SetValues(newRoutePhaseDirection); db.SaveChanges(); } catch (Exception e) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(Assembly.GetExecutingAssembly().GetName().ToString(), GetType().DisplayName(), e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, e.Message); throw new Exception(""); } } else { Add(newRoutePhaseDirection); } }
public void Update(Route newRoute) { var route = (from r in db.Routes where r.Id == newRoute.Id select r).FirstOrDefault(); if (route != null) { var newroute = new Route(); newroute.Id = route.Id; newroute.RouteName = newroute.RouteName; try { db.Entry(route).CurrentValues.SetValues(newroute); db.SaveChanges(); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteRepository"; error.Function = "UpdateByID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public void AddOrUpdate(DetectorComment detectorComment) { var 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 UpdateByRouteAndApproachID(int routeID, string signalId, int newOrderNumber) { var RouteDetail = (from r in db.RouteSignals where r.RouteId == routeID && r.SignalId == signalId select r).FirstOrDefault(); if (RouteDetail != null) { var newRouteDetail = new RouteSignal(); newRouteDetail.Order = newOrderNumber; try { db.Entry(RouteDetail).CurrentValues.SetValues(newRouteDetail); db.SaveChanges(); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteDetailsRepository"; error.Function = "UpdateByRouteAndApproachID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] SPMUser sPMUser) { if (ModelState.IsValid) { db.Entry(sPMUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sPMUser)); }
public ActionResult Edit([Bind(Include = "Id,Name")] SPMRole sPMRole) { if (ModelState.IsValid) { db.Entry(sPMRole).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sPMRole)); }
public void Update(Agency entity) { var agencyInDatabase = db.Agencies.Find(entity.AgencyID); if (agencyInDatabase == null) { Add(entity); } else { db.Entry(agencyInDatabase).CurrentValues.SetValues(entity); } }
public void Update(FAQ item) { var 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(Menu menuItem) { var 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(DetectionHardware DetectionHardware) { var 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(LaneType laneType) { var g = (from r in db.LaneTypes where r.LaneTypeID == laneType.LaneTypeID select r).FirstOrDefault(); if (g != null) { db.Entry(g).CurrentValues.SetValues(laneType); db.SaveChanges(); } else { db.LaneTypes.Add(laneType); db.SaveChanges(); } }
public void Update(SPMWatchDogErrorEvent SPMWatchDogErrorEvent) { var 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(ApplicationEvent applicationEvent) { var 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(MovementType movementType) { var 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(Detector detector) { var g = (from r in _db.Detectors where r.ID == detector.ID select r).FirstOrDefault(); if (g != null) { foreach (var i in detector.DetectionTypeIDs) { var t = (from r in _db.DetectionTypes where r.DetectionTypeID == i select r).FirstOrDefault(); detector.DetectionTypes.Add(t); } try { _db.Entry(g).CurrentValues.SetValues(detector); _db.SaveChanges(); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.DetectorRepository"; error.Function = "Update"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public void Update(Signal incomingSignal) { var signalFromDatabase = (from r in _db.Signals where r.VersionID == incomingSignal.VersionID select r).FirstOrDefault(); if (signalFromDatabase != null) { if (incomingSignal.VersionActionId == 0) { incomingSignal.VersionActionId = signalFromDatabase.VersionActionId; } _db.Entry(signalFromDatabase).CurrentValues.SetValues(incomingSignal); if (incomingSignal.Approaches != null) { foreach (var a in incomingSignal.Approaches) { var approach = signalFromDatabase.Approaches.FirstOrDefault(app => app.ApproachID == a.ApproachID); if (approach != null) { if (!a.Equals(approach)) { _db.Entry(approach).CurrentValues.SetValues(a); } } else { signalFromDatabase.Approaches.Add(a); } if (a.Detectors != null) { foreach (var newDetector in a.Detectors) { var detectorFromDatabase = signalFromDatabase.GetDetectorsForSignal() .FirstOrDefault(d => d.ID == newDetector.ID); 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(); var addedDetectionTypes = newDetector.DetectionTypes .Except(detectorFromDatabase.DetectionTypes).ToList(); deletedDetectionTypes.ForEach(delDet => detectorFromDatabase.DetectionTypes.Remove(delDet)); foreach (var 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 (var a in incomingSignal.Approaches) { foreach (var 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 AddOrUpdate(Approach approach) { var g = (from r in _db.Approaches where r.ApproachID == approach.ApproachID select r).FirstOrDefault(); if (approach.Detectors != null) { foreach (var det in approach.Detectors) { AddDetectiontypestoDetector(det); } } if (g != null) { try { _db.Entry(g).CurrentValues.SetValues(approach); _db.SaveChanges(); } catch (Exception ex) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent { ApplicationName = "MOE.Common", Class = "Models.Repository.ApproachRepository", Function = "Update", Description = ex.Message, SeverityLevel = ApplicationEvent.SeverityLevels.High, Timestamp = DateTime.Now }; repository.Add(error); throw; } } else { try { foreach (var 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) { var repository = ApplicationEventRepositoryFactory.Create(); var error = new ApplicationEvent { ApplicationName = "MOE.Common", Class = "Models.Repository.ApproachRepository", Function = "Add", Description = ex.Message, SeverityLevel = ApplicationEvent.SeverityLevels.High, Timestamp = DateTime.Now }; repository.Add(error); throw; } } }
public void Save(DatabaseArchiveSettings databaseArchiveSettings) { db.Entry(databaseArchiveSettings).State = EntityState.Modified; db.SaveChanges(); }