예제 #1
0
 public Aerolinea ConsultarAerolinea(int identificacion)
 {
     try
     {
         if (SiExisteAerolinea(identificacion))
         {
             Aerolinea aerolinea = new Aerolinea();
             using (aplication2Context ctx = new aplication2Context())
             {
                 aerolinea = ctx.Aerolinea.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.SaveChanges();
             }
             return(aerolinea);
         }
         else
         {
             Aerolinea aerolinea = new Aerolinea();
             return(aerolinea);
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #2
0
 public Prestamo ConsultarPrestamo(int identificacion)
 {
     try
     {
         if (SiExistePrestamo(identificacion))
         {
             Prestamo prestamo = new Prestamo();
             using (aplication2Context ctx = new aplication2Context())
             {
                 prestamo = ctx.Prestamo.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.SaveChanges();
             }
             return(prestamo);
         }
         else
         {
             Prestamo prestamo = new Prestamo();
             return(prestamo);
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #3
0
 public Aeronave ConsultarAeronave(int identificacion)
 {
     try
     {
         if (SiExisteAeronave(identificacion))
         {
             Aeronave aeronave = new Aeronave();
             using (aplication2Context ctx = new aplication2Context())
             {
                 aeronave.Estado           = SetEstado(identificacion);
                 ctx.Entry(aeronave).State = EntityState.Modified;
                 ctx.SaveChanges();
                 aeronave = ctx.Aeronave.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.SaveChanges();
             }
             return(aeronave);
         }
         else
         {
             Aeronave aeronave = new Aeronave();
             return(aeronave);
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #4
0
 public Ruta ConsultarRuta(int identificacion)
 {
     try
     {
         if (SiExisteRuta(identificacion))
         {
             Ruta ruta = new Ruta();
             using (aplication2Context ctx = new aplication2Context())
             {
                 ruta = ctx.Ruta.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.SaveChanges();
             }
             return(ruta);
         }
         else
         {
             Ruta ruta = new Ruta();
             return(ruta);
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #5
0
        public List <Aeronave> GetAeronave()
        {
            try
            {
                List <Aeronave> lstAeronave;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstAeronave = ctx.Aeronave.ToList();
                    foreach (Aeronave element in lstAeronave)
                    {
                        element.Estado           = SetEstado(element.Id);
                        ctx.Entry(element).State = EntityState.Modified;
                        ctx.SaveChanges();
                    }
                    lstAeronave = ctx.Aeronave.ToList();
                }

                return(lstAeronave);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #6
0
 public void AgregarRutas(DateTime inicio, DateTime final, int idAeronave, int idOrigen, int idDestino)
 {
     try
     {
         if (SiExisteAeronave(idAeronave) && SiExistePais(idOrigen) && SiExistePais(idDestino))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 if (ctx.Ruta.Where(x => x.IdAeronave == idAeronave).Any())
                 {
                     List <Ruta> rutas1 = (from p in ctx.Ruta where p.IdAeronave == idAeronave && p.Fechainicio <= inicio && p.Fechafin >= inicio select p).ToList();
                     List <Ruta> rutas2 = (from p in ctx.Ruta where p.IdAeronave == idAeronave && p.Fechainicio <= final && p.Fechafin >= final select p).ToList();
                     if (rutas1.Count() > 0 || rutas2.Count() > 0)
                     {
                         //error
                     }
                     else
                     {
                         if (inicio <= final)
                         {
                             Ruta ruta = new Ruta();
                             ruta.Fechainicio = inicio;
                             ruta.Fechafin    = final;
                             ruta.IdAeronave  = idAeronave;
                             ruta.IdOrigen    = idOrigen;
                             ruta.IdDestino   = idDestino;
                             ctx.Ruta.Add(ruta);
                             ctx.SaveChanges();
                         }
                     }
                 }
                 else
                 {
                     if (inicio <= final)
                     {
                         Ruta ruta = new Ruta();
                         ruta.Fechainicio = inicio;
                         ruta.Fechafin    = final;
                         ruta.IdAeronave  = idAeronave;
                         ruta.IdOrigen    = idOrigen;
                         ruta.IdDestino   = idDestino;
                         ctx.Ruta.Add(ruta);
                         ctx.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #7
0
 public void AgregarPrestamo(DateTime inicio, DateTime final, int idPopietario, int idPrestador, int idAeronave)
 {
     try
     {
         if (SiExisteAeronave(idPopietario) && SiExisteAerolinea(idPopietario) && SiExisteAerolinea(idPrestador))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 if (ctx.Prestamo.Where(x => x.Idaeronave == idAeronave).Any())
                 {
                     List <Prestamo> prestamo1 = (from p in ctx.Prestamo where p.Idaeronave == idAeronave && IsNotBetween(inicio, p.Fechainicio, p.Fechafin) select p).ToList();
                     List <Prestamo> prestamo2 = (from p in ctx.Prestamo where p.Idaeronave == idAeronave && IsNotBetween(final, p.Fechainicio, p.Fechafin)  select p).ToList();
                     if (prestamo1.Count() > 0 || prestamo2.Count() > 0)
                     {
                         //error
                     }
                     else
                     {
                         if (inicio <= final)
                         {
                             Prestamo prestamo = new Prestamo();
                             prestamo.Fechainicio   = inicio;
                             prestamo.Fechafin      = final;
                             prestamo.IdPropietario = idPopietario;
                             prestamo.IdPrestador   = idPrestador;
                             prestamo.Idaeronave    = idAeronave;
                             ctx.Prestamo.Add(prestamo);
                             ctx.SaveChanges();
                         }
                     }
                 }
                 else
                 {
                     if (inicio <= final)
                     {
                         Prestamo prestamo = new Prestamo();
                         prestamo.Fechainicio   = inicio;
                         prestamo.Fechafin      = final;
                         prestamo.IdPropietario = idPopietario;
                         prestamo.IdPrestador   = idPrestador;
                         prestamo.Idaeronave    = idAeronave;
                         ctx.Prestamo.Add(prestamo);
                         ctx.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #8
0
        public void ActualizarAeronave(int identificacion, decimal latitud, decimal longitud, bool estado)
        {
            Aeronave aeronave = ConsultarAeronave(identificacion);

            using (aplication2Context ctx = new aplication2Context())
            {
                aeronave.Latitud          = latitud;
                aeronave.Longitud         = longitud;
                aeronave.Estado           = SetEstado(identificacion);
                ctx.Entry(aeronave).State = EntityState.Modified;
                ctx.SaveChanges();
            }
        }
예제 #9
0
 private bool SiExisteAeronave(int identificacion)
 {
     using (aplication2Context ctx = new aplication2Context())
     {
         if (ctx.Aeronave.Where(x => x.Id == identificacion).Any())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #10
0
        public bool SetEstado(int identificacion)
        {
            DateTime Hoy = DateTime.Today;

            using (aplication2Context ctx = new aplication2Context())
            {
                if (ctx.Ruta.Where(x => x.IdAeronave == identificacion && x.Fechainicio >= Hoy && x.Fechainicio <= Hoy).Any())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #11
0
        public List <Prestamo> GetPrestamos()
        {
            try
            {
                List <Prestamo> lstPrestamo;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstPrestamo = ctx.Prestamo.ToList();
                }

                return(lstPrestamo);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #12
0
        public List <Aerolinea> GetAerolineas()
        {
            try
            {
                List <Aerolinea> lstAerolinea;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstAerolinea = ctx.Aerolinea.ToList();
                }

                return(lstAerolinea);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #13
0
        public List <Ruta> GetRutas()
        {
            try
            {
                List <Ruta> lstRuta;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstRuta = ctx.Ruta.ToList();
                }

                return(lstRuta);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #14
0
        public List <Ruta> GetRutasActuales()
        {
            try
            {
                DateTime    Hoy = DateTime.Today;
                List <Ruta> lstRutas;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstRutas = ctx.Ruta.Where(x => x.Fechainicio >= Hoy && x.Fechafin <= Hoy).ToList();
                }

                return(lstRutas);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #15
0
        public List <Prestamo> GetPrestamosActuales()
        {
            try
            {
                DateTime        Hoy = DateTime.Today;
                List <Prestamo> lstPrestamo;
                using (aplication2Context ctx = new aplication2Context())
                {
                    lstPrestamo = ctx.Prestamo.Where(x => x.Fechainicio >= Hoy && x.Fechafin <= Hoy).ToList();
                }

                return(lstPrestamo);
            }
            catch (Exception Ex)
            {
                string Message = Ex.Message;
                throw;
            }
        }
예제 #16
0
 public void BorrarRuta(int identificacion)
 {
     try
     {
         if (SiExisteRuta(identificacion))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 Ruta ruta = ctx.Ruta.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.Ruta.Remove(ruta);
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #17
0
 public void BorrarPrestamo(int identificacion)
 {
     try
     {
         if (SiExistePrestamo(identificacion))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 Prestamo prestamo = ctx.Prestamo.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.Prestamo.Remove(prestamo);
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #18
0
 public void BorrarAeronave(int identificacion)
 {
     try
     {
         if (SiExisteAeronave(identificacion))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 Aeronave aeronave = ctx.Aeronave.Where(x => x.Id == identificacion).FirstOrDefault();
                 ctx.Aeronave.Remove(aeronave);
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #19
0
 public void AgregarAerolinea(string name, int idpais)
 {
     try
     {
         if (SiExistePaisAerolinea(idpais))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 Aerolinea aerolinea = new Aerolinea();
                 aerolinea.Nombre = name;
                 aerolinea.IdPais = idpais;
                 ctx.Aerolinea.Add(aerolinea);
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }
예제 #20
0
 public void AgregarAeronave(decimal latitud, decimal longitud, bool estado, int idAerolinea)
 {
     try
     {
         if (SiExisteAerolinea(idAerolinea))
         {
             using (aplication2Context ctx = new aplication2Context())
             {
                 Aeronave aeronave = new Aeronave();
                 aeronave.Latitud     = latitud;
                 aeronave.Longitud    = longitud;
                 aeronave.Estado      = estado;
                 aeronave.IdAerolinea = idAerolinea;
                 ctx.Aeronave.Add(aeronave);
                 ctx.SaveChanges();
             }
         }
     }
     catch (Exception Ex)
     {
         string Message = Ex.Message;
         throw;
     }
 }