Exemple #1
0
        public async Task <IActionResult> Index(int page = 1)
        {
            try
            {
                TourSearchViewModel model = new TourSearchViewModel {
                    IsActive = true
                };
                model.Skip = (page - 1) * model.Fetch;
                int total = await tourDAL.GetTotalToursAsync();

                PageInfo pageInfo = new PageInfo
                {
                    TotalItems  = total,
                    ItemPerPage = model.Fetch,
                    PageAction  = nameof(Index),
                    CurrentPage = page
                };
                IEnumerable <Tour> tours = await tourDAL.GetAllToursAsync(model.Skip, model.Fetch);

                if (tours != null)
                {
                    foreach (Tour tour in tours)
                    {
                        tour.Destinations = await tourDAL.FindDestinationsByTourIdAsync(tour.Id);
                    }
                    model.Tours = tours;
                }
                model.PageInfo = pageInfo;
                ViewBag.Title  = "All Tours";
                return(View(model));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw;
            }
        }