Example #1
0
        public async Task <ActionResult <TripPlan> > PostTripPlan(TripPlan item)
        {
            _context.TripPlans.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTripPlan), new { id = item.Id }, item));
        }
Example #2
0
        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);
        }
Example #5
0
 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));
 }
Example #6
0
        // 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));
        }
Example #7
0
        // 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());
 }