public ActionResult FlightDetailsUpdate(FlightPlanDetails flight) { if (ModelState.IsValid) { AllDbContext context = new AllDbContext(); PlanesDbContext db = new PlanesDbContext(); ViewBag.PlaneID = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "PlaneID"); var items = context.Planes.Where(n => n.isAllotted == false); ViewBag.PlaneId = items; if (items != null) { ViewBag.data = items; } var pilot = db.Planes.Where(n => n.PlaneID == flight.PlaneID); foreach (var i in pilot) { i.isAllotted = true; } flight.isActive = true; flight.PilotID = User.Identity.GetUserName(); context.Flights.Add(flight); db.SaveChanges(); context.SaveChanges(); TempData["savedFlight"] = "Flight Details Added to Database Sucessfull!"; return(RedirectToAction("Index", "Pilot")); } return(View()); }
public ActionResult Planes() { var context = new PlanesDbContext(); List <PlaneDetails> planes = context.Planes.ToList(); return(View(planes)); }
public ActionResult AddPlanes(PlaneDetails planes) { if (ModelState.IsValid) { var context = new PlanesDbContext(); var isUnique = context.Planes.Where(n => n.PlaneID == planes.PlaneID || n.OwnerID == planes.OwnerID); foreach (var i in isUnique) { if (i.PlaneID == planes.PlaneID) { ViewData["PError"] = "PlaneID Already Exists"; return(View(planes)); } if (i.OwnerID == planes.OwnerID) { ViewData["OError"] = "OwnerID Already Exists"; return(View(planes)); } } context.Planes.Add(planes); context.SaveChanges(); TempData["planesSaved"] = "Planes Details Added Successfully!!"; return(RedirectToAction("Planes", "Admin")); } return(View()); }
public ActionResult UpdateFlightPlan(string id) { var db = new PlanesDbContext(); var db1 = new FlightDbContext(); ViewBag.PlaneID = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "PlaneID"); var flight = db1.Flights.FirstOrDefault(n => n.PlaneID == id); return(View(flight)); }
public ActionResult UpdatePlanes(string id) { var db = new PlanesDbContext(); var model = db.Planes.FirstOrDefault(r => r.PlaneID == id); if (model == null) { return(HttpNotFound()); } return(View(model)); }
public ActionResult FlightDetailsUpdate() { PlanesDbContext db = new PlanesDbContext(); var ps = new AdminDbContext(); var user = User.Identity.GetUserName(); var ps1 = ps.PilotS.FirstOrDefault(n => n.PilotID == user); var from = ps1.PilotAvailabilityFrom; ViewBag.PlaneID = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "PlaneID"); TempData["planSchedule"] = $"You can create Flight Plan in between {ps1.PilotAvailabilityFrom} to {ps1.PilotAvailabilityTo}"; return(View()); }
public ActionResult UpdateFlightPlan(FlightPlanDetails flightPlan) { PlanesDbContext db = new PlanesDbContext(); var db1 = new FlightDbContext(); ViewBag.PlaneID = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "PlaneID"); var flight = db1.Flights.FirstOrDefault(n => n.PlaneID == flightPlan.PlaneID); db1.SaveChanges(); return(View()); }
public ActionResult UpdatePlanes(PlaneDetails plane) { var db = new PlanesDbContext(); var entry = db.Entry(plane); if (ModelState.IsValid) { entry.State = EntityState.Modified; db.SaveChanges(); TempData["planesUpdate"] = "Plane Details Updated Successfully"; return(RedirectToAction("Planes", "Admin")); } return(View(entry)); }