Ejemplo n.º 1
0
        public Detector Add(Detector detector)
        {
            var 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)
                {
                    //var repository =
                    //    ApplicationEventRepositoryFactory.Create();
                    //var 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);
        }
Ejemplo n.º 2
0
        public void SetVersionToDeleted(int versionId)
        {
            var signal = (from r in _db.Signals where r.VersionID == versionId select r).FirstOrDefault();

            if (signal != null)
            {
                signal.VersionActionId = 3;
            }
            _db.SaveChanges();
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 6
0
        public void MoveRouteSignalUp(int routeId, int routeSignalId)
        {
            var route      = db.Routes.Find(routeId);
            var signal     = route.RouteSignals.FirstOrDefault(r => r.Id == routeSignalId);
            var order      = signal.Order;
            var swapSignal = route.RouteSignals.FirstOrDefault(r => r.Order == order - 1);

            if (swapSignal != null)
            {
                signal.Order--;
                swapSignal.Order++;
                db.SaveChanges();
            }
        }
Ejemplo n.º 7
0
 PreemptionAggregation IPreemptAggregationDatasRepository.Add(PreemptionAggregation preemptionAggregation)
 {
     db.PreemptionAggregations.Add(preemptionAggregation);
     db.SaveChanges();
     return(preemptionAggregation);
 }
Ejemplo n.º 8
0
        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;
                }
            }
        }