Example #1
0
        public static GTSLocationMessageCollection CreateGTSLocationMessages(Guid userId)
        {
            GTSLocationMessageCollection collection = new GTSLocationMessageCollection();

            GPSTrackerEntities1 dbContext = new GPSTrackerEntities1();



            IQueryable <TrackerUser> trackers = dbContext.TrackerUser.Where(m => m.UserId == userId);

            foreach (TrackerUser _tu in trackers)
            {
                IQueryable <LocationMessages> _messages =
                    dbContext.LocationMessages.Where(p => p.TrackerId == _tu.TrackerId);

                // need to get object representing the tracker information
                Trackers _trackerInfo = dbContext.Trackers.Where(p => p.Id == _tu.TrackerId).First();

                if (_messages.Count() > 0)
                {
                    DateTime         _maxTime = _messages.Max(p => p.ServerTime);
                    LocationMessages _message = _messages.Where(p => p.ServerTime == _maxTime).First();
                    collection.Add(CreateLocationMessage(_message, _trackerInfo));
                }
            }

            return(collection);
        }
Example #2
0
        public static GTSLocationMessageCollection CreateGTSLocationMessages(
            string id, DateTime sdateTime, DateTime edateTime)
        {
            GTSLocationMessageCollection collection = new GTSLocationMessageCollection();

            GPSTrackerEntities1 dbContext = new GPSTrackerEntities1();

            DateTime defaultDateTime = new DateTime(1900, 01, 01);

            sdateTime = sdateTime == DateTime.MinValue? defaultDateTime :sdateTime;
            edateTime = edateTime == DateTime.MinValue? defaultDateTime:edateTime;

            // used >= sdateTime here so that the system will update time when tracking with the javascript
            // may want to implement this differently for efficiency
            IOrderedQueryable <LocationMessages> messages =
                dbContext.LocationMessages.Where(m => m.TrackerId == id &&
                                                 (sdateTime == defaultDateTime || m.ServerTime >= sdateTime) &&
                                                 (edateTime == defaultDateTime || m.ServerTime < edateTime))
                .OrderBy(message => message.ServerTime);


            foreach (LocationMessages message in messages)
            {
                collection.Add(CreateLocationMessage(message));
            }

            return(collection);
        }