Exemplo n.º 1
0
 public List <Device> GetAll()
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices.ToList());
     }
 }
Exemplo n.º 2
0
 public Device GetById(int id)
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices.Where(x => x.Id == id).FirstOrDefault());
     }
 }
Exemplo n.º 3
0
 public void Delete(Device device)
 {
     using (var db = new PruebaPracticoContext())
     {
         db.Devices.Remove(device);
         db.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void Create(Device device)
 {
     using (var db = new PruebaPracticoContext())
     {
         db.Devices.Add(device);
         db.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public Device GetDeviceReportedLatest()
 {
     using (var db = new PruebaPracticoContext())
     {
         return(db.Devices
                .Where(x => x.Readings.Count > 0)
                .OrderBy(x => x.LastTimeReported)
                .FirstOrDefault());
     }
 }
Exemplo n.º 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();
     }
 }