Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 790
  • 1.1k
  • 53.9k

Booking date calculated wrongly

Apr 29 2024 9:47 AM

Hello Team,

In my project, I have the Room page and booking page, so at the booking page when I select the bookingFrom to bookingTo date, and the Room number I expected the room amount to multiple by the number of days book, but things are not working that way, kindly check it for me.

Database

Home Controller

public ActionResult RoomBooking()
{
    var objBookingViewModel = new BookingViewModel();
    var room = objHotelDbEntities.Rooms.ToList();
    objBookingViewModel.ListOfRoom = room.Select(obj => new SelectListItem

    {
        Text = obj.RoomNumber,
        Value = obj.RoomId.ToString(),
        Selected = false
    });
    objBookingViewModel.BookingFrom = DateTime.Now;
    objBookingViewModel.BookingTo = DateTime.Now.AddDays(1);        
    return View(objBookingViewModel);
} 


public ActionResult SaveRoomBooking(BookingViewModel objBookingViewModel)
{
    int numberOfDays = Convert.ToInt32((objBookingViewModel.BookingFrom - objBookingViewModel.BookingTo).TotalDays);
    Room objRoom = objHotelDbEntities.Rooms.Single(model => model.RoomId == objBookingViewModel.AssignRoomId);
    decimal RoomPrice = objRoom.RoomPrice;
    decimal TotalAmount = objRoom.RoomPrice * numberOfDays;

    RoomBooking roomBooking = new RoomBooking()
    {
        BookingFrom = objBookingViewModel.BookingFrom,
        BookingTo = objBookingViewModel.BookingTo,
        AssignRoomId = objBookingViewModel.AssignRoomId,
        Address = objBookingViewModel.Address,
        CustomerName = objBookingViewModel.CustomerName, 
        PhoneNo = objBookingViewModel.PhoneNo,
        NoOfMembers = objBookingViewModel.AssignRoomId,
        TotalAmount = objBookingViewModel.TotalAmount

    };
    objHotelDbEntities.RoomBookings.Add(roomBooking);
    objHotelDbEntities.SaveChanges();

    objRoom.BookingStatusId = 3;
    objHotelDbEntities.SaveChanges();
    return Json(new{message="Hotel Booking is Successfully Created.",success=true}, JsonRequestBehavior.AllowGet);
}

 


Answers (12)