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;
            }
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            try
            {
                IEnumerable <Tour> popularTours = await tourDAL.GetTrendingToursAsync();

                if (popularTours != null)
                {
                    foreach (Tour tour in popularTours)
                    {
                        tour.Destinations = await tourDAL.FindDestinationsByTourIdAsync(tour.Id);
                    }
                }
                AppUser user = User?.Identity?.Name == null ? null : await userManager.FindByNameAsync(User.Identity.Name);

                string avatar = "https://ztourist.blob.core.windows.net/others/avatar.png";
                if (user != null)
                {
                    avatar = user.Avatar;
                }

                if (cart != null && cart.Lines.Count() > 0)
                {
                    foreach (CartLine cartLine in cart.Lines)
                    {
                        cartLine.Tour = await tourDAL.FindTourByTourIdAsync(cartLine.Tour.Id);
                    }
                }
                NavigationViewModel model = new NavigationViewModel
                {
                    Cart         = cart,
                    PopularTours = popularTours,
                    Avatar       = avatar
                };
                return(View(model));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw;
            }
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            try
            {
                TourSearchViewModel model = new TourSearchViewModel();
                IEnumerable <Tour>  tours = await tourDAL.GetNearestToursAsync();

                if (tours != null)
                {
                    foreach (Tour tour in tours)
                    {
                        tour.Destinations = await tourDAL.FindDestinationsByTourIdAsync(tour.Id);
                    }
                    model.Tours = tours;
                }
                Dictionary <string, string> destinations = await destinationDAL.GetDestinationsIdNameAsync(null);

                model.DurationItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Below or in 2 Days", Value = "2"
                    },
                    new SelectListItem {
                        Text = "Below or in 5 Days", Value = "5"
                    },
                    new SelectListItem {
                        Text = "Below or in 1 Week", Value = "7"
                    },
                    new SelectListItem {
                        Text = "More than 1 week", Value = "8"
                    }
                };
                model.PriceItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Below 50$", Value = "1"
                    },
                    new SelectListItem {
                        Text = "50$ - 250$", Value = "2"
                    },
                    new SelectListItem {
                        Text = "250$ - 500$", Value = "3"
                    },
                    new SelectListItem {
                        Text = "500$ - 1000$", Value = "4"
                    },
                    new SelectListItem {
                        Text = "1000$ - 1500$", Value = "5"
                    },
                    new SelectListItem {
                        Text = "1500$ - 2000$", Value = "6"
                    },
                    new SelectListItem {
                        Text = "2000$ - 2500$", Value = "7"
                    },
                    new SelectListItem {
                        Text = "Upper 2500$", Value = "8"
                    }
                };
                if (destinations != null)
                {
                    model.DestinationItems = new SelectList(destinations, "Key", "Value");
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw;
            }
        }