Esempio n. 1
0
        public static void DeActivate(int id)
        {
            var q = db.Groups.First(x => x.GroupId == id);

            q.Status = false;
            db.SaveChanges();
        }
Esempio n. 2
0
        public static void RemoveGroupAlertsByGroupId(int groupId)
        {
            var gAlerts = db.GroupAlerts.Where(x => x.GroupId == groupId);

            foreach (var item in gAlerts)
            {
                db.GroupAlerts.DeleteObject(item);
            }
            db.SaveChanges();
        }
Esempio n. 3
0
        public bool UpdateVibe(int vibe, string phonenumber)
        {
            bool retval = true;
            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            // Create or overwrite LimerInfo for user
            LR_LimerInfo _info = context.LR_LimerInfo.Where(p => p.TrackerId == phonenumber).FirstOrDefault();

            if (_info == null)
            {
                retval = false;
            }
            else
            {
                _info.Vibe = vibe;

                try
                {
                    context.SaveChanges();
                }
                catch (System.Exception e)
                {
                    ExceptionHandler.HandleGeneralException(e);
                    retval = false;
                }
            }

            return(retval);
        }
Esempio n. 4
0
        public static void Save(AlertLog alertlog)
        {
            var db = new GPSTrackerEntities1();

            db.AlertLogs.AddObject(alertlog);
            db.SaveChanges();
        }
Esempio n. 5
0
        public static void Save(LocationMessageAlert locationMessageAlert)
        {
            var db = new GPSTrackerEntities1();

            db.LocationMessageAlerts.AddObject(locationMessageAlert);
            db.SaveChanges();
        }
        public bool Add(string trackerId, string mileageCount, string maintenanceNote)
        {
            try
            {
                //dirty
                GPSTrackerEntities1 context = new GPSTrackerEntities1();

                Maintenance m = context.Maintenance.CreateObject();

                m.trackerId        = trackerId;
                m.mileage          = Double.Parse(mileageCount);
                m.notes            = maintenanceNote;
                m.dateTimeRecorded = DateTime.Now;


                // Need to update table and last set location message?
                Trackers _tracker = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault();
                _tracker.Mileage = double.Parse(mileageCount);


                context.Maintenance.AddObject(m);
                context.SaveChanges();
                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
Esempio n. 7
0
        public static void Save(AlertFired alertFired)
        {
            var db = new GPSTrackerEntities1();

            db.AlertFireds.AddObject(alertFired);
            db.SaveChanges();
        }
Esempio n. 8
0
        /// <summary>
        /// Needs to be updated to update general tracking information
        /// </summary>
        /// <param name="?"></param>
        public static void UpdateTrackerInformation(LocationMessages message)
        {
            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            Trackers _tracker =
                context.Trackers.Where(t => t.Id == message.TrackerId).FirstOrDefault();

            _tracker.LastUpdate = DateTime.Now;
            _tracker.LastLat    = (new Latitude()
            {
                Degrees = message.LatDegrees, Minutes = message.LatMinutes, Seconds = message.LatSeconds, Heading = message.LatitudeHeading[0]
            }).Decimal;
            _tracker.LastLon    = (new Longitude()
            {
                Degrees = message.LngDegrees, Minutes = message.LngMinutes, Seconds = message.LngSeconds, Heading = message.LongitudeHeading[0]
            }).Decimal;

            if (message.Id != 0)
            {
                _tracker.LastLocationId = message.Id;
            }


            context.SaveChanges();
        }
Esempio n. 9
0
        public static void UpdateByTrackerId(string trackerId)
        {
            var db   = new GPSTrackerEntities1();
            var data = db.LocationMessageAlerts.FirstOrDefault(x => x.TrackerId == trackerId && x.IsProcessed == false);

            data.IsProcessed = true;
            db.SaveChanges();
        }
Esempio n. 10
0
        public static void ProcessedAlertExitFired(int id)
        {
            var db   = new GPSTrackerEntities1();
            var data = db.AlertFireds.FirstOrDefault(x => x.Id == id);

            // data.IsEnter = true;
            data.IsExit = true;
            data.Active = false;
            db.SaveChanges();
        }
Esempio n. 11
0
        public static void Save(GeoFence geoFence)
        {
            if (geoFence.FencesId == 0)
            {
                geoFence.CreatedDate = DateTime.Now;
                db.GeoFences.AddObject(geoFence);
            }

            geoFence.UpdatedDate = DateTime.Now;
            db.SaveChanges();
        }
Esempio n. 12
0
        public bool CompleteRegistration(string fname, string lname, string phonenumber, string passcode)
        {
            bool retval = true;
            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            LR_Passcode pass = context.LR_Passcode.Where(p => p.phonenumber == phonenumber).FirstOrDefault();

            retval = pass != null && pass.Passcode.Trim() == passcode.Trim();

            if (retval)
            {
                Trackers newTracker = context.Trackers.Where(t => t.Id == phonenumber).FirstOrDefault();
                // test that this works if tracker does not exist and if it does exist
                if (newTracker == null)
                {
                    newTracker = new Trackers();
                    context.Trackers.AddObject(newTracker);
                    newTracker.Id = phonenumber;
                }

                newTracker.Name   = fname + " " + lname;
                newTracker.Type   = "TYPMB";
                newTracker.Status = "LR002";

                // Create or overwrite LimerInfo for user
                LR_LimerInfo _info = context.LR_LimerInfo.Where(p => p.TrackerId == phonenumber).FirstOrDefault();

                if (_info == null)
                {
                    _info = new LR_LimerInfo();
                    context.LR_LimerInfo.AddObject(_info);
                    _info.TrackerId = phonenumber;
                }

                _info.Vibe    = 1;
                _info.Status  = 3;
                _info.Message = "Hey, I'm on LimeR!!!";

                try
                {
                    context.SaveChanges();
                }
                catch (System.Exception e)
                {
                    ExceptionHandler.HandleGeneralException(e);
                    retval = false;
                }
            }
            return(retval);
        }
Esempio n. 13
0
        public static bool UpdateTrackerInformation(CellLocationMessage message)
        {
            bool retval = true;

            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            Trackers _tracker =
                context.Trackers.Where(t => t.Id == message.TrackerID).FirstOrDefault();

            _tracker.LastUpdate = DateTime.Now;
            _tracker.LastLat    = message.Latitude.Decimal;
            _tracker.LastLon    = message.Longitude.Decimal;


            context.SaveChanges();


            return(retval);
        }
Esempio n. 14
0
        /// <summary>
        /// Needs to be updated to update general tracking information
        /// </summary>
        /// <param name="?"></param>
        public static void UpdateTrackerInformation(GTSLocationMessage message)
        {
            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            Trackers _tracker =
                context.Trackers.Where(t => t.Id == message.TrackerID).FirstOrDefault();

            _tracker.LastUpdate = DateTime.Now;
            _tracker.LastLat    = message.Latitude.Decimal;
            _tracker.LastLon    = message.Longitude.Decimal;

            if (message.Id != 0)
            {
                _tracker.LastLocationId = message.Id;
            }


            context.SaveChanges();
        }
Esempio n. 15
0
        // Method that shares the tracker information with Security Personel Assigned
        // Currently First Response TODO: Update to assign response team based on location or something

        public static bool AlertSecurity(string trackerId)
        {
            // First response User Id 172D2D4A-8711-48EC-9ADE-D0660D4568E0

            GPSTrackerEntities1 context = new GPSTrackerEntities1();

            try
            {
                TrackerUser tu = TrackerUser.CreateTrackerUser(1, trackerId, new Guid("172D2D4A-8711-48EC-9ADE-D0660D4568E0"), true);

                context.AddToTrackerUser(tu);
                context.SaveChanges();
            }
            catch (System.Exception e)
            {
                ExceptionHandler.HandleGeneralException(e);
                return(false);
            }
            return(true);
        }
Esempio n. 16
0
        public void SaveEvents(List <Event> events)
        {
            // if event id exist, then update
            GTSDataStorage.Event eventt;

            foreach (Event e in events)
            {
                if (e.EventId == 0)
                {
                    eventt = GTSDataStorage.Event.CreateEvent(0, e.EventDescription, e.GetTrackerEventType, e.Time, e.ObjectId);
                    eventt.ExtendedProperties = e.ExtendedProperties;
                    context.AddToEvents(eventt);
                }
                else
                {
                    eventt                    = context.Events.Where(t => t.Id == e.EventId).FirstOrDefault();
                    eventt.Description        = e.EventDescription;
                    eventt.ExtendedProperties = e.ExtendedProperties;
                }
                context.SaveChanges();
            }
        }
Esempio n. 17
0
        public bool StartSMSRegistration(string phonenumber)
        {
            GPSTrackerEntities1 context = new GPSTrackerEntities1();
            bool retval = true;


            // Get 4 digit random pass code
            string passcode = getPasscode();

            // Send pascode to phone number
            retval = retval && sendSMS(phonenumber, "This is your passcode: " + passcode);

            // save pass code and phone number to table. Check to see if exist already


            LR_Passcode passCode = context.LR_Passcode.Where(p => p.phonenumber == phonenumber).FirstOrDefault();

            if (passCode == null)
            {
                passCode = new LR_Passcode();
                context.AddToLR_Passcode(passCode);
            }

            passCode.Passcode    = passcode;
            passCode.phonenumber = phonenumber;

            try
            {
                context.SaveChanges();
            }
            catch (System.Exception e)
            {
                retval = false;
            }

            return(retval);
        }
Esempio n. 18
0
        public static void SaveTrackerInformation(GTSLocationMessage message)
        {
            GTSLocationMessage  prevMessage = getLastLocationMessage(message.TrackerID);
            GPSTrackerEntities1 context     = new GPSTrackerEntities1();
            LocationMessages    msg;
            double mileage;

            // Update total milage TODO: we need to add in the engine on check here!!!! After we put engine on as a standard on all vehicles
            if (message.Speed != 0)
            {
                //Calculate what the mileage on the tracker should be

                try
                {
                    //get the Tracker (this is probably done elsewhere, so it's an extra hit)
                    Trackers _tracker = context.Trackers.Where(t => t.Id == message.TrackerID).FirstOrDefault();

                    //if we didnt have a mileage reading before, get it from Tracker if it exists, else assume it's 0 and start counting from there.

                    double mileageChange;

                    if (_tracker.Mileage.HasValue && _tracker.Mileage.Value > 0.0)
                    {
                        mileageChange = Utilities.CalculateDistanceBetween(_tracker.LastLat.Value, _tracker.LastLon.Value, message.Latitude.Decimal, message.Longitude.Decimal);

                        mileage = _tracker.Mileage.Value + mileageChange;
                        //update tracker mileage value too
                    }
                    else
                    {
                        mileage = 0;
                    }
                    _tracker.Mileage = mileage;

                    //saving here to make sure we don't throw off anything else later down by doing a batch save
                    // this is a wasted DB hit though.
                    context.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    //swallow for now
                    mileage = 0.0;
                }
            }
            else
            {
                mileage = prevMessage != null?prevMessage.Mileage.GetValueOrDefault() : 0;
            }

            if (prevMessage == null || prevMessage.Speed != 0 || message.Speed != 0 ||
                Math.Abs(prevMessage.Latitude.Decimal - message.Latitude.Decimal) > 0.001 ||
                Math.Abs(prevMessage.Longitude.Decimal - message.Longitude.Decimal) > 0.001 ||
                prevMessage.Status != message.Status)
            {
                // add new message into messages
                msg = LocationMessages.CreateLocationMessages(1, message.RawLocationMessageData, message.Latitude.Degrees
                                                              , message.Latitude.Minutes, message.Latitude.Seconds, message.Longitude.Degrees, message.Longitude.Minutes
                                                              , message.Longitude.Seconds, message.ServerRecordedDateTime, message.TrackerID,
                                                              message.Latitude.Heading.ToString(), message.Longitude.Heading.ToString(), message.Speed, message.IdleTime,
                                                              message.Direction, message.Status, message.ClientRecordedDateTime, message.HDOP, message.VDOP,
                                                              message.Altitude, message.Status, message.Input1, message.Input2,
                                                              message.DInput1, message.DInput2, message.DInput3, message.DInput4, message.DInput5, mileage);

                context.AddToLocationMessages(msg);
                int affectedRows = context.SaveChanges();
                message.Id = msg.Id;
            }
            else
            {
                // update time on previous message
                //weird..... must be some better way of architechting this...... as well should be exception handeled!!!

                //vs: If it's in the same spot, we don't need to do anything with mileage

                TimeSpan span = message.ServerRecordedDateTime.Subtract(prevMessage.ServerRecordedDateTime);
                prevMessage.IdleTime = span.Ticks;

                msg = context.LocationMessages.Where(m => m.Id == prevMessage.Id).First();
                message.IdleTime = msg.IdleTime = prevMessage.IdleTime;

                context.SaveChanges();
            }
            if (msg != null)
            {
                UpdateTrackerInformation(msg);
            }

            // Events pulled from information in the Location Messages
            // All Hooks so far for events are here - lets keep it so until needed
            List <Events.Event> events = new Events.Management().GetVT310eEvents(message, prevMessage);

            new Events.Management().SaveEvents(events);
            Utilities.writeLine("Debug 30: Message Saved!");
        }
Esempio n. 19
0
 public static void Add(TrackerFenceMap trackerFenceMap)
 {
     db.AddToTrackerFenceMaps(trackerFenceMap);
     db.SaveChanges();
 }
Esempio n. 20
0
 public static void Add(UserFenceMap userFenceMap)
 {
     db.AddToUserFenceMaps(userFenceMap);
     db.SaveChanges();
 }