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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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(); } }
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; } }
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; } }
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; } }
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; } }
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; } }