Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 783
  • 1.1k
  • 54.7k

Date format not working

Nov 18 2024 11:12 AM

Hello Team,

In my mvc controller  and Js function my date formart became like this /Date(1728086400000)/ mean while in other part of project this same date format work fine as I expected.

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 (2)