1
Answer

Date format not working

Gaurav Kr

Gaurav Kr

6h
2
1
public ActionResult GetAllBookingHistory(string RoomNumber, string sDate=null, string eDate=null)
{
    DateTime? startDate = null;
    if (!string.IsNullOrEmpty(sDate))
        startDate = Convert.ToDateTime(sDate);
    DateTime? endDate = null;
    if (!string.IsNullOrEmpty(eDate))
        endDate = Convert.ToDateTime(eDate);
    var bookingList = objHotelDbEntities.RoomBookings.Join(objHotelDbEntities.Rooms,
                      booking => booking.AssignRoomId,
                      room => room.RoomId,
                      (booking, room) => new { booking = booking, room = room });
    var modifiedData = bookingList.GroupBy(x => new { x.booking.BookingFrom, x.booking.BookingTo, x.booking.BookingId}).Select(x => new RoomBookingViewModel
    {
        CustomerName = x.FirstOrDefault().booking.CustomerName,
        Address = x.FirstOrDefault().booking.Address,
        PhoneNo = x.FirstOrDefault().booking.PhoneNo,
        BookingFrom = x.Key.BookingFrom,
        BookingTo = x.Key.BookingTo,
        BookingId = x.FirstOrDefault().booking.BookingId,
        RoomNumber = x.FirstOrDefault().room.RoomNumber,
        NoOfMembers = x.FirstOrDefault().booking.NoOfMembers,
        numberOfDays = System.Data.Entity.DbFunctions.DiffDays(x.Key.BookingFrom, x.Key.BookingTo).Value,
        RoomPrice = x.FirstOrDefault().room.RoomPrice,
        TotalAmount = x.FirstOrDefault().booking.TotalAmount,

    }).ToList();
    modifiedData.ForEach(a => { a.BookingFrom = Convert.ToDateTime(a.BookingFrom); });
    if(startDate !=null)
    {
        modifiedData = modifiedData.Where(a => a.BookingFrom >= startDate).ToList();
    }
    if(endDate !=null)
    {
        modifiedData = modifiedData.Where(a => a.BookingFrom <= endDate).ToList();
    }
    var responseData = modifiedData.OrderBy(a => a.BookingFrom).ToList();
    var TotalSales = responseData.Sum(a => a.TotalAmount);
    return Json(modifiedData, JsonRequestBehavior.AllowGet);
}

 

Answers (1)