コード例 #1
0
        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;
            }
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 public void Add(Models.ActionLog entity)
 {
     if (entity.Actions == null)
     {
         entity.Actions = db.Actions
                          .Where(a => entity.ActionIDs.Contains(a.ActionID)).ToList();
     }
     if (entity.MetricTypes == null)
     {
         entity.MetricTypes = db.MetricTypes
                              .Where(a => entity.MetricTypeIDs.Contains(a.MetricID)).ToList();
     }
     db.ActionLogs.Add(entity);
     db.SaveChanges();
 }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
 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();
     }
 }
コード例 #8
0
ファイル: LaneRepository.cs プロジェクト: zfx1982/ATSPM
 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();
     }
 }
コード例 #9
0
 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();
     }
 }
コード例 #10
0
ファイル: ApproachRepository.cs プロジェクト: zfx1982/ATSPM
        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;
                }
            }
        }
コード例 #11
0
 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();
     }
 }
コード例 #12
0
ファイル: Converter.cs プロジェクト: zfx1982/ATSPM
 public void SaveSignalsToDB()
 {
     db.Signals.AddRange(SignalsList.Distinct());
     Console.WriteLine("Saving Signals");
     db.SaveChanges();
 }
コード例 #13
0
 public void Save(Models.WatchDogApplicationSettings watchDogApplicationSettings)
 {
     db.Entry(watchDogApplicationSettings).State = EntityState.Modified;
     db.SaveChanges();
 }
コード例 #14
0
 public void Add(Models.Menu menuItem)
 {
     db.Menus.Add(menuItem);
     db.SaveChanges();
 }
コード例 #15
0
 public void Add(Models.FAQ item)
 {
     db.FAQs.Add(item);
     db.SaveChanges();
 }
コード例 #16
0
        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;
            }
        }
コード例 #17
0
 public void Save()
 {
     db.SaveChanges();
 }
コード例 #18
0
ファイル: Converter.cs プロジェクト: zfx1982/ATSPM
        public void SaveSignalsToDB()
        {
            db.Signals.AddRange(SignalsList.Distinct());

            db.SaveChanges();
        }