Example #1
0
 public List <Device> GetAll()
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices.ToList());
     }
 }
Example #2
0
 public Device GetById(int id)
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices.Where(x => x.Id == id).FirstOrDefault());
     }
 }
Example #3
0
 public void Delete(Device device)
 {
     using (var db = new PruebaPracticoContext())
     {
         db.Devices.Remove(device);
         db.SaveChanges();
     }
 }
Example #4
0
 public void Create(Device device)
 {
     using (var db = new PruebaPracticoContext())
     {
         db.Devices.Add(device);
         db.SaveChanges();
     }
 }
Example #5
0
 public Device GetDeviceReportedLatest()
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices
                .Where(x => x.Readings.Count > 0)
                .OrderBy(x => x.LastTimeReported)
                .FirstOrDefault());
     }
 }
Example #6
0
 public void Update(Device device)
 {
     using (var db = new PruebaPracticoContext())
     {
         var savedDevice = db.Devices.Where(x => x.Id == device.Id).FirstOrDefault();
         if (savedDevice == null)
         {
             return;
         }
         db.Entry(savedDevice).CurrentValues.SetValues(savedDevice);
         db.SaveChanges();
     }
 }