public async Task <IActionResult> Search(TourSearchViewModel model, int page = 1) { try { if (model == null) { model = new TourSearchViewModel(); } model.InitSearchValues(); model.IsActive = true; // customer or anomymous user only search active tour model.Skip = (page - 1) * model.Fetch; int total = await tourDAL.GetTotalSearchToursAsync(model); PageInfo pageInfo = new PageInfo { TotalItems = total, ItemPerPage = model.Fetch, PageAction = nameof(Search), CurrentPage = page }; IEnumerable <Tour> tours = await tourDAL.SearchToursAsync(model); if (tours != null) { foreach (Tour tour in tours) { tour.Destinations = await tourDAL.FindDestinationsByTourIdAsync(tour.Id); } model.Tours = tours; } model.PageInfo = pageInfo; ViewBag.Title = "Search Tours"; return(View("Index", model)); } catch (Exception ex) { logger.Error(ex.Message); throw; } }