private FilterCarResultModel UpdateFilter(ProductCarRental model, FormCollection collection, FilterCarParamModel filterParamModel, string tripid) { List <VehVendorAvail> carList = new List <VehVendorAvail>(); var result = model.Result.VehAvailRSCore.VehVendorAvails.DeepCopy(); carList.AddRange(result.VehVendorAvail); List <VehVendorAvail> _preProcessedList = carList; int totaldays = Convert.ToInt32((model.Result.VehAvailRSCore.VehRentalCore.ReturnDateTime.Value.Date - model.Result.VehAvailRSCore.VehRentalCore.PickUpDateTime.Value.Date).TotalDays); FilterCarResultModel filterModel = new FilterCarResultModel(); if (Core.GetSession(Enumeration.SessionName.FilterHotelResult, tripid) != null) { filterModel = (FilterCarResultModel)Core.GetSession(Enumeration.SessionName.FilterCarRentalResult, tripid); } if (filterParamModel != null) { #region STAR rating if (!string.IsNullOrEmpty(filterParamModel.Rating)) { decimal _rateStarParse = filterParamModel.Rating.ToDecimal(); _preProcessedList = _preProcessedList.Where(x => x.VehAvails.VehAvailCore.Vehicle.OctaneRating.ToString() == filterParamModel.Rating).ToList(); } #endregion #region Property name if (!string.IsNullOrWhiteSpace(filterParamModel.CarModel)) { string PropertyName = filterParamModel.CarModel; _preProcessedList = _preProcessedList.Where(x => x.VehAvails.VehAvailCore.Vehicle.VehicleName.ToLower().Contains(PropertyName.ToLower()) || x.VehAvails.VehAvailCore.Vehicle.VehicleModel.Model.ToLower().Contains(PropertyName.ToLower()) || x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.GroupName.ToLower().Contains(PropertyName.ToLower())).ToList(); } #endregion #region SortBy vehicle group if (!string.IsNullOrWhiteSpace(filterParamModel.SortBy)) { string vehicleGrp = filterParamModel.SortBy; _preProcessedList = _preProcessedList.Where(x => x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.GroupName == vehicleGrp).ToList(); } #endregion #region Location Near Filter if (!string.IsNullOrWhiteSpace(filterParamModel.minPrice) && !string.IsNullOrWhiteSpace(filterParamModel.maxPrice)) { decimal MinPrice = filterParamModel.minPrice.ToDecimal(); decimal MaxPrice = filterParamModel.maxPrice.ToDecimal(); _preProcessedList = _preProcessedList.Where(x => x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.SeatNumber >= MinPrice && x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.SeatNumber <= MaxPrice).ToList(); } #endregion } // Execute result filterModel.FilResult = _preProcessedList; filterModel.FilterSettings = filterParamModel; filterModel.FilterSettings.defaultMin = result.VehVendorAvail.Min(x => x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.SeatNumber) ?? 0; filterModel.FilterSettings.defaultMax = result.VehVendorAvail.Max(x => x.VehAvails.VehAvailCore.Vehicle.VehicleGroup.SeatNumber) ?? 0; Core.SetSession(Enumeration.SessionName.FilterCarRentalResult, tripid, filterModel); return(filterModel); }
public async Task <ActionResult> GetCarRentalList(int?page, FormCollection collection, ProductCarRental.FilterCarParamModel filterParamModel, string tripid, string rType = null, string newsearch = null) { collection = collection ?? new FormCollection(); CheckoutProduct CheckoutModel = (CheckoutProduct)Core.GetSession(Enumeration.SessionName.CheckoutProduct, tripid); CheckoutModel = CheckoutModel ?? new CheckoutProduct(); var model = CheckoutModel.CarRental; model.SearchInfo.CurrentViewPage = (page ?? model.SearchInfo.CurrentViewPage); int pageNumber = model.SearchInfo.CurrentViewPage; int pageSize = 10; int.TryParse(Core.GetAppSettingValueEnhanced("RecordsPerPage"), out pageSize); try { if ((model.SearchInfo.locationCode != null && model.SearchInfo.PickupDateTime != DateTime.MinValue && model.SearchInfo.ReturnDateTime != DateTime.MinValue) && page == null && (model.Result == null || newsearch == "1")) { List <string> pushEvErrMsg = new List <string>(); model.Result = await GetCarRentalListFromSearchInfo(model.SearchInfo); if (model.Result?.Errors != null && model.Result?.Errors?.ErrorMessage != "No record found!") { var _jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, }; Logger.Error(Environment.NewLine + "Error return from search car rental service." + Environment.NewLine + Environment.NewLine + JsonConvert.SerializeObject(model, Formatting.Indented, _jsonSetting)); ViewBag.SysErrMsg = "Sorry, unexpected error occur."; } else if (model.Result?.Errors?.ErrorMessage == "No record found!") { ViewBag.SysErrMsg = "No record found!"; } } FilterCarResultModel filtResult = new FilterCarResultModel(); IPagedList <VehVendorAvail> IPagedModel = null; if (model.Result != null && model.Result.Success == "true") { if (Core.GetSession(Enumeration.SessionName.FilterCarRentalResult, tripid) == null || filterParamModel != null && (filterParamModel.Rating != null || filterParamModel.minPrice != null || filterParamModel.maxPrice != null || filterParamModel.CarModel != null || filterParamModel.SortBy != null)) { filtResult = UpdateFilter(model, collection, filterParamModel, tripid); Core.SetSession(Enumeration.SessionName.FilterCarRentalResult, tripid, filtResult); IPagedModel = filtResult.FilResult.ToPagedList(1, pageSize); // every new filter also need reset page number to 1 } else { filtResult = (FilterCarResultModel)Core.GetSession(Enumeration.SessionName.FilterCarRentalResult, tripid); IPagedModel = filtResult.FilResult.ToPagedList(pageNumber, pageSize); } filtResult.MarkupInfo = GetMarkup(model.SearchInfo); ViewData.Add("RESULT", filtResult.FilResult.Count > 0 ? filtResult.FilResult : null); filtResult.IPagedCarList = IPagedModel; model.FilterCarResult = filtResult; } } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.Debug(ex, "GetCarRentalList()"); } return(Request.IsAjaxRequest() ? (ActionResult)PartialView("~/Views/CarRental/_CarRentalList.cshtml", model) : RedirectToAction("Search")); }