public ScheduleVehicle IsScheduleBooked(VehicleInformation vehicle, DateTime selectedDate, string shift)
 {
     try
     {
         SqlConnectionObj.Open();
         string query = string.Format("SELECT * FROM ScheduleVehicle WHERE VehicleRegNo='{0}' AND Date='{1}' AND Shift='{2}'", vehicle.RegNo, selectedDate, shift);
         SqlCommandObj.CommandText = query;
         SqlDataReader reader = SqlCommandObj.ExecuteReader();
         while (reader.Read())
         {
             ScheduleVehicle vehicleSchedule = new ScheduleVehicle();
             vehicleSchedule.Vehicle.RegNo = reader[0].ToString();
             vehicleSchedule.SelectedDate  = (DateTime)reader[1];
             vehicleSchedule.SelectShift   = reader[2].ToString();
             vehicleSchedule.BookedBy      = reader[3].ToString();
             vehicleSchedule.Address       = reader[4].ToString();
             return(vehicleSchedule);
         }
     }
     catch (Exception exceptionObj)
     {
         throw new Exception("Exception occured! In Schedule Booking.", exceptionObj);
     }
     finally
     {
         if (SqlConnectionObj != null && SqlConnectionObj.State == ConnectionState.Open)
         {
             SqlConnectionObj.Close();
         }
     }
     return(null);
 }
        public ActionResult ViewScheduleOfVehicles(int?id)
        {
            ////ViewBag.ShiftId = new SelectList(db.Shifts, "Id", "Shifts");
            ////ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "RegNo");
            ////return View();


            //ScheduleVehicle schedulevehicle = db.ScheduleVehicles.Find(id);
            //ViewBag.Data = schedulevehicle;
            ////if (schedulevehicle == null)
            ////{
            ////    return HttpNotFound();
            ////}
            //return View(ViewBag.Data);
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ScheduleVehicle schedulevehicle = db.ScheduleVehicles.Find(id);

            if (schedulevehicle == null)
            {
                return(HttpNotFound());
            }
            return(View(schedulevehicle));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ScheduleVehicle schedulevehicle = db.ScheduleVehicles.Find(id);

            db.ScheduleVehicles.Remove(schedulevehicle);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,VehicleId,Date,ShiftId,BookedBy,Address")] ScheduleVehicle schedulevehicle)
 {
     if (ModelState.IsValid)
     {
         db.Entry(schedulevehicle).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ShiftId   = new SelectList(db.Shifts, "Id", "Shifts", schedulevehicle.ShiftId);
     ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "RegNo", schedulevehicle.VehicleId);
     return(View(schedulevehicle));
 }
Ejemplo n.º 5
0
        public bool IsScheduleBooked(VehicleInformation vehicle, DateTime selectedDate, string shift)
        {
            ScheduleVehicle vehicleSchedule = new ScheduleVehicle();

            vehicleSchedule = scheduleVehicleGateway.IsScheduleBooked(vehicle, selectedDate, shift);
            if (vehicleSchedule != null)
            {
                string msg = string.Format("This schedule is already booked by : {0}", vehicleSchedule.BookedBy);
                return(true);
            }
            return(false);
        }
        // GET: /ScheduleVehicle/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ScheduleVehicle schedulevehicle = db.ScheduleVehicles.Find(id);

            if (schedulevehicle == null)
            {
                return(HttpNotFound());
            }
            return(View(schedulevehicle));
        }
        // GET: /ScheduleVehicle/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ScheduleVehicle schedulevehicle = db.ScheduleVehicles.Find(id);

            if (schedulevehicle == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ShiftId   = new SelectList(db.Shifts, "Id", "Shifts", schedulevehicle.ShiftId);
            ViewBag.VehicleId = new SelectList(db.Vehicles, "Id", "RegNo", schedulevehicle.VehicleId);
            return(View(schedulevehicle));
        }