Пример #1
0
 public Detector Add(Models.Detector detector)
 {
     Models.Detector g = (from r in db.Detectors
                          where r.ID == detector.ID
                          select r).FirstOrDefault();
     if (g == null)
     {
         detector.DetectionTypes = new List <DetectionType>();
         detector.DetectionTypes = db.DetectionTypes.Where(dt => detector.DetectionTypeIDs.Contains(dt.DetectionTypeID)).ToList();;
         try
         {
             db.Detectors.Add(detector);
             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.DetectorRepository";
             error.Function        = "Add";
             error.Description     = ex.Message;
             error.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
             error.Timestamp       = DateTime.Now;
             repository.Add(error);
             throw;
         }
     }
     return(detector);
 }
        public void DeleteByRouteID(int routeID)
        {
            List <Models.ApproachRouteDetail> routes = (from r in db.ApproachRouteDetails
                                                        where r.ApproachRouteId == routeID
                                                        select r).ToList();

            try
            {
                db.ApproachRouteDetails.RemoveRange(routes);
                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.ApproachRouteDetailsRepository";
                error.Function        = "DeleteByRouteID";
                error.Description     = ex.Message;
                error.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
                error.Timestamp       = DateTime.Now;
                repository.Add(error);
                throw;
            }
        }
Пример #3
0
        public void DeleteByID(int routeID)
        {
            Models.ApproachRoute route = (from r in db.ApproachRoutes
                                          where r.ApproachRouteId == routeID
                                          select r).FirstOrDefault();

            db.ApproachRoutes.Remove(route);
            db.SaveChanges();
        }
Пример #4
0
 private void Save()
 {
     try
     {
         MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
         {
             MOE.Common.Models.Speed_Events se = new MOE.Common.Models.Speed_Events();
             se.DetectorID = this.sensorId;
             se.timestamp  = this.date;
             se.MPH        = this.mph;
             se.KPH        = this.kph;
             Regex r = new Regex("^[a-zA-Z0-9]*$");
             if (r.IsMatch(se.DetectorID))
             {
                 db.Speed_Events.Add(se);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateException ex)
     {
         SqlException innerException = ex.InnerException.InnerException as SqlException;
         if (innerException != null && (innerException.Number == 2627 || innerException.Number == 2601))
         {
         }
         else
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
                                      MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
         }
     }
     catch (Exception ex)
     {
         MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
             MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
         eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
                                  MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
     }
 }
Пример #5
0
 private void Save()
 {
     try
     {
         MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
         {
             MOE.Common.Models.Speed_Events se = new MOE.Common.Models.Speed_Events();
             se.DetectorID = this.sensorId;
             se.timestamp  = this.date;
             se.MPH        = this.mph;
             se.KPH        = this.kph;
             Regex r = new Regex("^[a-zA-Z0-9]*$");
             if (r.IsMatch(se.DetectorID))
             {
                 db.Speed_Events.Add(se);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateException ex)
     {
         //NOTE: I think trying to write to the applicaiton log when the DB is unavailbe is making the serivce crash more than it needs too.
         SqlException innerException = ex.InnerException.InnerException as SqlException;
         if (innerException != null && (innerException.Number == 2627 || innerException.Number == 2601))
         {
         }
         else
         {
             //applicationEventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
             //    MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
         }
     }
     catch (Exception ex)
     {
         //applicationEventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
         //    MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
     }
 }
Пример #6
0
 public void InsertRoute(Models.Route route)
 {
     db.Routes.Add(route);
     db.SaveChanges();
 }