public async Task <ActionResult <TripPlan> > PostTripPlan(TripPlan item) { _context.TripPlans.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTripPlan), new { id = item.Id }, item)); }
public ActionResult DeleteConfirmed(int id) { TripPlan tripPlan = db.TripPlan.Find(id); db.TripPlan.Remove(tripPlan); db.SaveChanges(); return(RedirectToAction("Index")); }
public string Put([FromBody] TripPlan model) { var tripPlan = (TripPlan)repository.GetById(model.Id); if (tripPlan.HasEmptySpot()) { tripPlan.SeatsTaken++; repository.Update(tripPlan); } return(Constants.SUCCESSUPDATE); }
public string AddNewTrip([FromBody] TripPlan model) { var newTripPlan = (TripPlan)repository.GetById(model.Id); if (newTripPlan != null) { return(Constants.ErrorCodeAlreadyAdded); } repository.Add(model); return(Constants.SUCCESSINSERT); }
public ActionResult Edit([Bind(Include = "Id,Day,Id_trip,Id_driver,Id_worker,Id_buss")] TripPlan tripPlan) { if (ModelState.IsValid) { db.Entry(tripPlan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_buss = new SelectList(db.Buss, "Id", "name", tripPlan.Id_buss); ViewBag.Id_trip = new SelectList(db.Trip, "Id", "name", tripPlan.Id_trip); ViewBag.Id_driver = new SelectList(db.Users, "Id", "login", tripPlan.Id_driver); ViewBag.Id_worker = new SelectList(db.Users, "Id", "login", tripPlan.Id_worker); return(View(tripPlan)); }
// GET: TripPlans/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TripPlan tripPlan = db.TripPlan.Find(id); if (tripPlan == null) { return(HttpNotFound()); } return(View(tripPlan)); }
// GET: TripPlans/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TripPlan tripPlan = db.TripPlan.Find(id); if (tripPlan == null) { return(HttpNotFound()); } ViewBag.Id_buss = new SelectList(db.Buss, "Id", "name", tripPlan.Id_buss); ViewBag.Id_trip = new SelectList(db.Trip, "Id", "name", tripPlan.Id_trip); ViewBag.Id_driver = new SelectList(db.Users, "Id", "login", tripPlan.Id_driver); ViewBag.Id_worker = new SelectList(db.Users, "Id", "login", tripPlan.Id_worker); return(View(tripPlan)); }
public static bool HasEmptySpot(this TripPlan tripPlan) { return(tripPlan.NumberOfSeats != tripPlan.SeatsTaken); }
public override int GetHashCode() { return(TripPlan.GetHashCode()); }