Beispiel #1
0
        public ActionResult Update(int parkingID, int bookingID, string bookingDateTime, int hours)
        {
            ParkingBooking ParkingBooking = db.ParkingBookings.Find(bookingID);

            ParkingBooking.ParkingID   = parkingID;
            ParkingBooking.BookingTime = Convert.ToDateTime(bookingDateTime);
            ParkingBooking.Hours       = hours;
            db.SaveChanges();
            return(RedirectToAction("Bookings"));
        }
Beispiel #2
0
        public ActionResult Delete(int?id)
        {
            string userID = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(userID))
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                SqlParameter[] sqlparams = new SqlParameter[2];
                sqlparams[0] = new SqlParameter("@user_id", userID);
                sqlparams[1] = new SqlParameter("@booking_id", id);
                string         query   = "select * from ParkingBookings where BookingID = @booking_id AND UserId = @user_id";
                ParkingBooking booking = db.ParkingBookings.SqlQuery(query, sqlparams).FirstOrDefault();

                return(View(booking));
            }
        }
Beispiel #3
0
        public ActionResult UpdateBooking(int?id)
        {
            string userID = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(userID))
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                List <Parking> parkings      = db.Parkings.ToList();
                ParkingUpdate  parkingUpdate = new ParkingUpdate();
                SqlParameter[] sqlparams     = new SqlParameter[2];
                sqlparams[0] = new SqlParameter("@userID", userID);
                sqlparams[1] = new SqlParameter("@id", id);
                ParkingBooking booking = db.ParkingBookings.SqlQuery("select * from ParkingBookings where BookingID = @id AND UserId = @userID", sqlparams).FirstOrDefault();
                parkingUpdate.Parkings       = parkings;
                parkingUpdate.ParkingBooking = booking;
                Debug.WriteLine(parkingUpdate.ParkingBooking.BookingTime);
                return(View(parkingUpdate));
            }
        }
Beispiel #4
0
        public ActionResult AddBooking(int parkingID, string bookingDateTime, int hours)
        {
            Debug.WriteLine(bookingDateTime);
            string userID = User.Identity.GetUserId();

            if (string.IsNullOrEmpty(userID))
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                ParkingBooking booking = new ParkingBooking();
                booking.ParkingID   = parkingID;
                booking.Hours       = hours;
                booking.UserId      = User.Identity.GetUserId();
                booking.BookingTime = Convert.ToDateTime(bookingDateTime);

                // Equivalent to SQL insert statement:
                db.ParkingBookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Bookings"));
            }
        }