예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
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);
 }
예제 #4
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);
        }
예제 #5
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);
 }
예제 #6
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);
 }