Пример #1
0
        public ActionResult Add(PiSpyDevice model)
        {
            if (ModelState.IsValid)
            {
                ApplicationDbContext db = new ApplicationDbContext();
                string appUserId = db.Users.Single(m => m.UserName == User.Identity.Name).Id;
                model.ApplicationUserId = appUserId;
                db.PiSpyDevices.Add(model);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(model);
        }
Пример #2
0
        public ActionResult Edit(PiSpyDevice model)
        {
            if (ModelState.IsValid)
            {
                ApplicationDbContext db = new ApplicationDbContext();
                var piSpy = db.PiSpyDevices.Find(model.Id);

                piSpy.Name = model.Name;
                piSpy.SerialNumber = model.SerialNumber;
                piSpy.Location = model.Location;
                piSpy.Notes = model.Notes;
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            return View("Add", model);
        }
Пример #3
0
        public DataViewModel(int piSpyId, DateTime? startTime = null, DateTime? endTime = null)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            PiSpyDevice = db.PiSpyDevices.Find(piSpyId);

            StartTime = startTime ?? DateTime.Now.AddHours(-29); // db.PiSpyDataLogs.First(m => m.PiSpySerialNumber == PiSpyDevice.SerialNumber).TimeStamp; // passed in value OR the first recorded data point from that PiSpy
            EndTime = endTime ?? DateTime.Now.AddHours(-5); // passed in value OR the current time in central time // subtracting 5 hours for the time zone difference

            var difference = (DateTime)EndTime - (DateTime)StartTime;

            Delta = (int)Math.Round(difference.TotalSeconds / 6);

            this.DataLogs = db.PiSpyDataLogs.Where(m =>
                m.PiSpySerialNumber == PiSpyDevice.SerialNumber
                && (StartTime == null || m.TimeStamp >= StartTime)
                && (EndTime == null || m.TimeStamp <= EndTime))
                .ToList();
        }
Пример #4
0
 public MySpiesViewModel(PiSpyDevice dev)
 {
     PiSpyDevice = dev;
 }