Example #1
0
        public bool AddReading(TrackerReadingModel model)
        {
            int affectedRows = 0;

            using (var db = new trackerwebdbEntities())
            {
                //look up monitor
                Monitor monitor = db.Monitors.Where(x => x.IpAddress == model.IpAddress).FirstOrDefault();
                if (monitor != null)
                {
                    //update last ping
                    monitor.LastPing = model.Reading;

                    //look up tag
                    Tag tag = db.Tags.Where(x => x.TagId == model.TagId).FirstOrDefault();
                    if (tag != null)
                    {
                        Tracking t = null;
                        //get latest tag readings (keep most recent 3)
                        var historicReadings = db.Trackings.Where(x => x.TagId == tag.Id).OrderByDescending(x => x.Reading).ToList();
                        if (historicReadings.Count > 0)
                        {
                            //most recent reading first, check to see if location has changed
                            var mostRecent = historicReadings.First();
                            if (mostRecent.MonitorId == monitor.Id)
                            {
                                //just update reading
                                mostRecent.Reading = model.Reading;
                            }
                            else
                            {
                                //add reading -- only keep 3 of the last locations total per tag
                                if (historicReadings.Count == 3)
                                {
                                    db.Trackings.Remove(historicReadings[2]);
                                }
                                t           = new Tracking();
                                t.MonitorId = monitor.Id;
                                t.TagId     = tag.Id;
                                t.Reading   = model.Reading;
                                db.Trackings.Add(t);
                            }
                        }
                        else
                        {
                            //no history simply add
                            t           = new Tracking();
                            t.MonitorId = monitor.Id;
                            t.TagId     = tag.Id;
                            t.Reading   = model.Reading;
                            db.Trackings.Add(t);
                        }
                        affectedRows = db.SaveChanges();
                    } //end find tag
                }     // end find monitor
            }         //end using statement
            return(affectedRows > 0);
        }
        public bool AddReading(TrackerReadingModel model)
        {
            int affectedRows = 0;

            using(var db = new trackerwebdbEntities())
            {
                //look up monitor
                Monitor monitor = db.Monitors.Where(x => x.IpAddress == model.IpAddress).FirstOrDefault();
                if (monitor != null)
                {
                    //update last ping
                    monitor.LastPing = model.Reading;

                    //look up tag
                    Tag tag = db.Tags.Where(x => x.TagId == model.TagId).FirstOrDefault();
                    if (tag != null)
                    {
                        Tracking t = null;
                        //get latest tag readings (keep most recent 3)
                        var historicReadings = db.Trackings.Where(x => x.TagId == tag.Id).OrderByDescending(x => x.Reading).ToList();
                        if(historicReadings.Count > 0)
                        {
                            //most recent reading first, check to see if location has changed
                            var mostRecent = historicReadings.First();
                            if(mostRecent.MonitorId == monitor.Id)
                            {
                                //just update reading
                                mostRecent.Reading = model.Reading;
                            }
                            else
                            {
                                //add reading -- only keep 3 of the last locations total per tag
                                if (historicReadings.Count == 3)
                                {
                                    db.Trackings.Remove(historicReadings[2]);
                                }
                                t = new Tracking();
                                t.MonitorId = monitor.Id;
                                t.TagId = tag.Id;
                                t.Reading = model.Reading;
                                db.Trackings.Add(t);
                            }
                        }
                        else 
                        {
                            //no history simply add
                            t = new Tracking();
                            t.MonitorId = monitor.Id;
                            t.TagId = tag.Id;
                            t.Reading = model.Reading;
                            db.Trackings.Add(t);
                        }
                        affectedRows = db.SaveChanges();
                    } //end find tag
                } // end find monitor
            }//end using statement
            return affectedRows > 0;
        }
 public Tag GetTagById(int id)
 {
     Tag retvalue = null;
     using (var db = new trackerwebdbEntities())
     {
         retvalue = db.Tags.Where(x => x.Id == id).FirstOrDefault();
     }
     return retvalue;
 }
 public Monitor GetMonitorById(int id)
 {
     Monitor retvalue = null;
     using(var db = new trackerwebdbEntities())
     {
         retvalue = db.Monitors.Where(x => x.Id == id).FirstOrDefault();
     }
     return retvalue;
 }
 public List<InventoryView> GetCurrentInventory()
 {
     List<InventoryView> retvalue = null;
     using(var db = new trackerwebdbEntities())
     {
         retvalue = db.InventoryViews.ToList();
     }
     return retvalue;
 }
 public List<Tag> GetAllTags()
 {
     List<Tag> retvalue = null;
     using (var db = new trackerwebdbEntities())
     {
         retvalue = db.Tags.ToList();
     }
     return retvalue;
 }
 public List<Monitor> GetAllMonitors()
 {
     List<Monitor> retvalue = null;
     using(var db = new trackerwebdbEntities())
     {
         retvalue = db.Monitors.ToList();
     }
     return retvalue;
 }
Example #8
0
        public Tag GetTagById(int id)
        {
            Tag retvalue = null;

            using (var db = new trackerwebdbEntities())
            {
                retvalue = db.Tags.Where(x => x.Id == id).FirstOrDefault();
            }
            return(retvalue);
        }
Example #9
0
        public Monitor GetMonitorById(int id)
        {
            Monitor retvalue = null;

            using (var db = new trackerwebdbEntities())
            {
                retvalue = db.Monitors.Where(x => x.Id == id).FirstOrDefault();
            }
            return(retvalue);
        }
Example #10
0
        public List <InventoryView> GetCurrentInventory()
        {
            List <InventoryView> retvalue = null;

            using (var db = new trackerwebdbEntities())
            {
                retvalue = db.InventoryViews.ToList();
            }
            return(retvalue);
        }
Example #11
0
        public List <Tag> GetAllTags()
        {
            List <Tag> retvalue = null;

            using (var db = new trackerwebdbEntities())
            {
                retvalue = db.Tags.ToList();
            }
            return(retvalue);
        }
Example #12
0
        public List <Monitor> GetAllMonitors()
        {
            List <Monitor> retvalue = null;

            using (var db = new trackerwebdbEntities())
            {
                retvalue = db.Monitors.ToList();
            }
            return(retvalue);
        }
 public bool AddMonitor(Monitor monitor)
 {
     int affectedRows = 0;
     using(var db = new trackerwebdbEntities())
     {
         monitor.Status = 1;
         db.Monitors.Add(monitor);
         affectedRows = db.SaveChanges();
     }
     return affectedRows > 0;
 }
Example #14
0
 public bool AddTag(Tag Tag)
 {
     int affectedRows = 0;
     using (var db = new trackerwebdbEntities())
     {
         Tag.Status = 1;
         db.Tags.Add(Tag);
         affectedRows = db.SaveChanges();
     }
     return affectedRows > 0;
 }
Example #15
0
        public bool AddTag(Tag Tag)
        {
            int affectedRows = 0;

            using (var db = new trackerwebdbEntities())
            {
                Tag.Status = 1;
                db.Tags.Add(Tag);
                affectedRows = db.SaveChanges();
            }
            return(affectedRows > 0);
        }
Example #16
0
        public bool AddMonitor(Monitor monitor)
        {
            int affectedRows = 0;

            using (var db = new trackerwebdbEntities())
            {
                monitor.Status = 1;
                db.Monitors.Add(monitor);
                affectedRows = db.SaveChanges();
            }
            return(affectedRows > 0);
        }
 public bool UpdateMonitor(Monitor monitor)
 {
     int affectedRows = 0;
     using(var db = new trackerwebdbEntities())
     {
         //update mac, friendly name, location and status
         var model = db.Monitors.Where(x => x.Id == monitor.Id).First();
         model.IpAddress = monitor.IpAddress;
         model.FriendlyName = monitor.FriendlyName;
         model.Location = monitor.Location;
         model.Status = monitor.Status;
         affectedRows = db.SaveChanges();
     }
     return affectedRows > 0;
 }
Example #18
0
 public bool UpdateTag(Tag Tag)
 {
     int affectedRows = 0;
     using (var db = new trackerwebdbEntities())
     {
         //update tagid, friendly name, description and (future) image blob
         var model = db.Tags.Where(x => x.Id == Tag.Id).First();
         model.TagId = Tag.TagId;
         model.FriendlyName = Tag.FriendlyName;
         model.Description = Tag.Description;
         model.Status = Tag.Status;
         affectedRows = db.SaveChanges();
     }
     return affectedRows > 0;
 }
Example #19
0
        public bool UpdateMonitor(Monitor monitor)
        {
            int affectedRows = 0;

            using (var db = new trackerwebdbEntities())
            {
                //update mac, friendly name, location and status
                var model = db.Monitors.Where(x => x.Id == monitor.Id).First();
                model.IpAddress    = monitor.IpAddress;
                model.FriendlyName = monitor.FriendlyName;
                model.Location     = monitor.Location;
                model.Status       = monitor.Status;
                affectedRows       = db.SaveChanges();
            }
            return(affectedRows > 0);
        }
Example #20
0
        public bool UpdateTag(Tag Tag)
        {
            int affectedRows = 0;

            using (var db = new trackerwebdbEntities())
            {
                //update tagid, friendly name, description and (future) image blob
                var model = db.Tags.Where(x => x.Id == Tag.Id).First();
                model.TagId        = Tag.TagId;
                model.FriendlyName = Tag.FriendlyName;
                model.Description  = Tag.Description;
                model.Status       = Tag.Status;
                affectedRows       = db.SaveChanges();
            }
            return(affectedRows > 0);
        }