public bool NewIncomingTravel(Travel newTravel) { using (AirNautisEntities airNautis = new AirNautisEntities()) { Airplane selectedAirplane = (from ap in airNautis.Airplane where ap.Id == newTravel.Airplane select ap).First(); Hangar selectedHangar = GetHangar(int.Parse(newTravel.Destination)); int counter = GetAirplanesByHangar(int.Parse(newTravel.Destination)).Count(); if (counter < selectedHangar.Capacity) { Travel travel = new Travel(); travel.Date = DateTime.Now; travel.Airplane = selectedAirplane.Id; travel.Origin = newTravel.Origin; travel.Destination = "Hangar " + selectedHangar.Number.ToString(); selectedAirplane.Hangar = selectedHangar.Number; airNautis.SaveChanges(); airNautis.Travel.Add(travel); airNautis.SaveChanges(); return(true); } } return(false); }
public bool NewOutgoingTravel(Travel newTravel) { using (AirNautisEntities airNautis = new AirNautisEntities()) { Airplane selectedAirplane = (from ap in airNautis.Airplane where ap.Id == newTravel.Airplane select ap).First(); if (newTravel.Destination != null) { Travel travel = new Travel(); travel.Date = DateTime.Now; travel.Airplane = selectedAirplane.Id; travel.Origin = "Hangar " + selectedAirplane.Hangar.ToString(); travel.Destination = newTravel.Destination; selectedAirplane.Hangar = null; airNautis.SaveChanges(); airNautis.Travel.Add(travel); airNautis.SaveChanges(); return(true); } } return(false); }
public bool CreateHangar(Hangar newHangar) { using (AirNautisEntities airNautis = new AirNautisEntities()) { if (newHangar.Capacity > 0) { airNautis.Hangar.Add(newHangar); airNautis.SaveChanges(); return(true); } } return(false); }
//INSERT public bool InsertAirplane(Airplane newAirplane) { using (AirNautisEntities airNautis = new AirNautisEntities()) { if (newAirplane.Model != null && newAirplane.Capacity > 0 && newAirplane.Capacity < 1000 && newAirplane.Year >= 1970 && newAirplane.Year <= 2013) { airNautis.Airplane.Add(newAirplane); airNautis.SaveChanges(); return(true); } } return(false); }
public bool ActivateAirplane(int airplane_id) { using (AirNautisEntities airNautis = new AirNautisEntities()) { Airplane a = (from ap in airNautis.Airplane where ap.Id == airplane_id select ap).First(); if (a != null) { a.Active = true; airNautis.SaveChanges(); return(true); } } return(false); }
//EDIT public Boolean EditAirplane(Airplane airplane) { using (AirNautisEntities airNautis = new AirNautisEntities()) { Airplane a = (from ap in airNautis.Airplane where ap.Id == airplane.Id select ap).First(); if (airplane.Model != null && airplane.Capacity > 0 && airplane.Capacity < 1000 && airplane.Year >= 1970 && airplane.Year <= 2013) { a.Model = airplane.Model; a.Year = airplane.Year; a.Capacity = airplane.Capacity; a.Hangar = airplane.Hangar; airNautis.SaveChanges(); return(true); } } return(false); }