public ActionResult DeleteConfirmed(int id)
        {
            CustomBooking customBooking = db.CustomBookings.Find(id);

            db.CustomBookings.Remove(customBooking);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
        public static bool dateLessChecker1(CustomBooking roomBooking)
        {
            bool check = false;

            if (roomBooking.CheckInDate < DateTime.Now)
            {
                check = true;
            }
            return(check);
        }
        public ActionResult Create([Bind(Include = "RoomBookingId,RoomType,RoomId,GuestEmail,RoomPrice,Total,CheckInDate,CheckOutDate,NumberOfDays,NumberOfPeople,NumberOfRooms,Status,HotelAddress,ManagerEmail")] CustomBooking roomBooking)
        {
            var userName = User.Identity.GetUserName();
            //roomBooking.RoomId = int.Parse(Session["RoomId"].ToString());

            var recordss = db.RoomBookings.Where(x => x.RoomId == roomBooking.RoomId).Select(x => x.CheckOutDate).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (roomBooking.CheckInDate >= recordss)
                {
                    if (BusinessLogic.dateLessChecker1(roomBooking) == false)
                    {
                        if (BusinessLogic.dateLessChecker1(roomBooking) == false)
                        {
                            roomBooking.GuestEmail   = userName;
                            roomBooking.ManagerEmail = BusinessLogic.GetHotelManagerEmail(roomBooking.RoomId);
                            roomBooking.RoomPrice    = BusinessLogic.GetRoomPrice(roomBooking.RoomId);
                            roomBooking.RoomType     = BusinessLogic.GetRoomType(roomBooking.RoomId);
                            roomBooking.NumberOfDays = BusinessLogic.GetNumberDays(roomBooking.CheckInDate, roomBooking.CheckOutDate);
                            roomBooking.Status       = "Not yet Checked In!!";
                            roomBooking.Total        = BusinessLogic.calcTotalRoomCost1(roomBooking);
                            roomBooking.HotelAddress = BusinessLogic.GetHotelAddress(roomBooking.RoomId);

                            db.CustomBookings.Add(roomBooking);
                            db.SaveChanges();
                            Session["bookID"] = roomBooking.RoomBookingId;
                            ViewBag.RoomId    = new SelectList(db.Rooms, "RoomId", "roomDescription", roomBooking.RoomId);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Check in date cannot be greater than checkout date!!");
                            ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", roomBooking.RoomId);
                            return(View(roomBooking));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Cannot book for a date that has passed!!");
                        ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", roomBooking.RoomId);
                        return(View(roomBooking));
                    }
                }
                else
                {
                    ModelState.AddModelError("", $"Room already booked!! Please Choose date after {recordss}");
                    ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", roomBooking.RoomId);
                    return(View(roomBooking));
                }
            }
            ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", roomBooking.RoomId);
            return(View(roomBooking));
        }
 public ActionResult Edit([Bind(Include = "RoomBookingId,RoomType,RoomId,GuestEmail,RoomPrice,Total,CheckInDate,CheckOutDate,NumberOfDays,NumberOfPeople,NumberOfRooms,Status,HotelAddress,ManagerEmail")] CustomBooking customBooking)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customBooking).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", customBooking.RoomId);
     return(View(customBooking));
 }
        // GET: CustomBookings/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomBooking customBooking = db.CustomBookings.Find(id);

            if (customBooking == null)
            {
                return(HttpNotFound());
            }
            return(View(customBooking));
        }
示例#6
0
        public static bool roomChecker1(CustomBooking roomBooking)
        {
            bool     check   = false;
            DateTime outDate = (from r in db.RoomBookings
                                where r.RoomId == roomBooking.RoomId
                                select r.CheckOutDate
                                ).FirstOrDefault();

            if (roomBooking.CheckInDate <= outDate)
            {
                check = true;
            }
            return(check);
        }
        // GET: CustomBookings/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomBooking customBooking = db.CustomBookings.Find(id);

            if (customBooking == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "roomDescription", customBooking.RoomId);
            return(View(customBooking));
        }
示例#8
0
 public static decimal calcTotalRoomCost1(CustomBooking roomBooking)
 {
     return(GetRoomPrice(roomBooking.RoomId) * GetNumberDays(roomBooking.CheckInDate, roomBooking.CheckOutDate));
 }