Example #1
0
 public Pico ObtenerPico(int id)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             return(db.Picos.Find(id));
         }
     } catch (Exception) { }
     return(null);
 }
Example #2
0
 public int EliminarSector(int id)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             db.Sectores.Remove(db.Sectores.Find(id));
             return(db.SaveChanges());
         }
     } catch (Exception) { }
     return(0);
 }
Example #3
0
 public int EditarSector(int id, string nuevoNombre)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             Sector sector = db.Sectores.Find(id);
             sector.Nombre = nuevoNombre;
             return(db.SaveChanges());
         }
     } catch (Exception) { }
     return(0);
 }
Example #4
0
 public int EditarPico(int id, string nuevoNombre)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             Pico pico = db.Picos.Find(id);
             pico.Nombre = nuevoNombre;
             return(db.SaveChanges());
         }
     } catch (Exception) { }
     return(0);
 }
Example #5
0
 public Sector ObtenerSector(int id)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             Sector sector = db.Sectores
                             .Include("Picos")
                             .Where((Sector s) => s.Id == id)
                             .FirstOrDefault(null);
         }
     } catch (Exception) { }
     return(null);
 }
Example #6
0
        public Sector CrearSector(string nombre)
        {
            Sector sector = new Sector {
                Nombre = nombre
            };

            try {
                using (var db = new ModeloBDPicos()) {
                    sector = db.Sectores.Add(sector);
                    db.SaveChanges();
                }
            } catch (Exception ex)  { }
            return(sector);
        }
Example #7
0
 public List <Sector> ListarSectores(bool incluirPicos = false)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             if (incluirPicos)
             {
                 return(db.Sectores
                        .Include("Picos")
                        .ToList());
             }
             return(db.Sectores.ToList());
         }
     } catch (Exception) { }
     return(new List <Sector>());
 }
Example #8
0
 public Pico CrearPico(int id, string nombre, int idSector)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             Sector sector = db.Sectores
                             .Include("Picos")
                             .SingleOrDefault(s => s.Id == idSector);
             if (sector != null)
             {
                 Pico pico = sector.CrearPico(id, nombre);
                 db.SaveChanges();
                 return(pico);
             }
         }
     } catch (Exception ex) { }
     return(null);
 }
Example #9
0
 public List <Pico> ListarPicos(bool incluirSectores = false)
 {
     try {
         using (var db = new ModeloBDPicos()) {
             if (!incluirSectores)
             {
                 return(db.Picos.ToList());
             }
             else
             {
                 return(db.Picos
                        .Include("Sector")
                        .ToList <Pico>());
             }
         }
     } catch (Exception) { }
     return(new List <Pico>());
 }
Example #10
0
 public int EditarPico(int id, int nuevoId, string nuevoNombre, int idSector, int idSectorNuevo)
 {
     try {
         if (id != nuevoId)
         {
             if (idSector != idSectorNuevo)
             {
                 Pico pico = CrearPico(nuevoId, nuevoNombre, idSectorNuevo);
                 EliminarPico(id);
                 if (pico != null)
                 {
                     return(1);
                 }
             }
             using (var db = new ModeloBDPicos()) {
                 Sector sector = db.Sectores
                                 .Include("Picos")
                                 .SingleOrDefault(s => s.Id == idSector);
                 Pico pico = sector.FindPico(id);
                 pico.Id     = nuevoId;
                 pico.Nombre = nuevoNombre;
                 return(db.SaveChanges());
             }
         }
         if (idSector != idSectorNuevo)
         {
             EliminarPico(id);
             Pico pico = CrearPico(nuevoId, nuevoNombre, idSectorNuevo);
             if (pico != null)
             {
                 return(1);
             }
         }
         using (var db = new ModeloBDPicos()) {
             Sector sector = db.Sectores
                             .Include("Picos")
                             .SingleOrDefault(s => s.Id == idSector);
             sector.FindPico(id).Nombre = nuevoNombre;
             return(db.SaveChanges());
         }
     } catch (Exception) { }
     return(0);
 }