Hello Team,
I want to implement data filtering, by using date range to filter the booking and the final column will sum up below as shown on the screenshot.
CONTROLLER METHOD.
public ActionResult GetAllBookingHistoryPDF(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 AllBookingDetail { 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.Sum(a=>a.booking.TotalAmount) }).ToList(); if (!string.IsNullOrEmpty(sDate) && !string.IsNullOrEmpty(eDate)) { DateTime fromDate = DateTime.Parse(sDate); DateTime toDate = DateTime.Parse(eDate); modifiedData = modifiedData.Where(a => (a.BookingFrom) >= fromDate && (a.BookingTo) <= toDate).OrderBy(x => x.BookingFrom).ToList(); } decimal total = 0; if (modifiedData != null && modifiedData.Count() > 0) { total = modifiedData.Sum(a => a.TotalAmount) }
return Json(modifiedData, JsonRequestBehavior.AllowGet); }