Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <Tour> > SearchToursAsync(TourSearchViewModel search)
        {
            List <Tour> result = null;
            Tour        tour;

            try
            {
                using (SqlConnection cnn = new SqlConnection(connectionStr))
                {
                    SqlCommand cmd;
                    if (string.IsNullOrEmpty(search.Destination))
                    {
                        cmd = new SqlCommand("spSearchTours", cnn);
                    }
                    else
                    {
                        cmd = new SqlCommand("spSearchToursIncludeDestinationId", cnn);
                    }
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Skip", search.Skip);
                    cmd.Parameters.AddWithValue("@Fetch", search.Fetch);
                    if (!string.IsNullOrEmpty(search.Id))
                    {
                        cmd.Parameters.AddWithValue("@Id", $"%{search.Id}%");
                    }
                    if (!string.IsNullOrEmpty(search.Name))
                    {
                        cmd.Parameters.AddWithValue("@Name", $"%{search.Name}%");
                    }
                    if (!string.IsNullOrEmpty(search.Destination))
                    {
                        cmd.Parameters.AddWithValue("@DestinationId", search.Destination);
                    }
                    if (search.FromDate != null)
                    {
                        cmd.Parameters.AddWithValue("@FromDate", search.FromDate);
                    }
                    if (search.Duration > 0 && search.Duration < 8)
                    {
                        cmd.Parameters.AddWithValue("@Duration", search.Duration * 24);
                    }
                    if (search.MinPrice != null)
                    {
                        cmd.Parameters.AddWithValue("@MinPrice", search.MinPrice);
                    }
                    if (search.MaxPrice != null)
                    {
                        cmd.Parameters.AddWithValue("@MaxPrice", search.MaxPrice);
                    }
                    if (search.IsActive == null)
                    {
                        cmd.Parameters.AddWithValue("@IsActive", true);
                        cmd.Parameters.AddWithValue("@IsActiveCheck", false);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@IsActive", search.IsActive);
                        cmd.Parameters.AddWithValue("@IsActiveCheck", search.IsActive);
                    }

                    if (cnn.State == ConnectionState.Closed)
                    {
                        cnn.Open();
                    }
                    using (SqlDataReader sdr = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
                    {
                        if (sdr.HasRows)
                        {
                            result = new List <Tour>();
                            while (await sdr.ReadAsync())
                            {
                                tour             = new Tour();
                                tour.Id          = sdr.GetString(sdr.GetOrdinal("Id"));
                                tour.Name        = sdr.GetString(sdr.GetOrdinal("Name"));
                                tour.Description = sdr.GetString(sdr.GetOrdinal("Description"));
                                tour.FromDate    = sdr.GetDateTime(sdr.GetOrdinal("FromDate"));
                                tour.ToDate      = sdr.GetDateTime(sdr.GetOrdinal("ToDate"));
                                tour.Transport   = sdr.GetString(sdr.GetOrdinal("Transport"));
                                tour.AdultFare   = sdr.GetDecimal(sdr.GetOrdinal("AdultFare"));
                                tour.KidFare     = sdr.GetDecimal(sdr.GetOrdinal("KidFare"));
                                tour.Image       = sdr.GetString(sdr.GetOrdinal("Image"));
                                tour.Duration    = sdr.GetInt32(sdr.GetOrdinal("Duration"));
                                result.Add(tour);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
        public async Task <int> GetTotalSearchToursAsync(TourSearchViewModel search)
        {
            int result = 0;

            try
            {
                using (SqlConnection cnn = new SqlConnection(connectionStr))
                {
                    SqlCommand cmd;
                    if (string.IsNullOrEmpty(search.Destination))
                    {
                        cmd = new SqlCommand("spGetTotalSearchTours", cnn);
                    }
                    else
                    {
                        cmd = new SqlCommand("spGetTotalSearchToursIncludeDestinationId", cnn);
                    }
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (!string.IsNullOrEmpty(search.Id))
                    {
                        cmd.Parameters.AddWithValue("@Id", $"%{search.Id}%");
                    }
                    if (!string.IsNullOrEmpty(search.Name))
                    {
                        cmd.Parameters.AddWithValue("@Name", $"%{search.Name}%");
                    }
                    if (!string.IsNullOrEmpty(search.Destination))
                    {
                        cmd.Parameters.AddWithValue("@DestinationId", search.Destination);
                    }
                    if (search.FromDate != null)
                    {
                        cmd.Parameters.AddWithValue("@FromDate", search.FromDate);
                    }
                    if (search.Duration > 0 && search.Duration < 8)
                    {
                        cmd.Parameters.AddWithValue("@Duration", search.Duration * 24);
                    }
                    if (search.MinPrice != null)
                    {
                        cmd.Parameters.AddWithValue("@MinPrice", search.MinPrice);
                    }
                    if (search.MaxPrice != null)
                    {
                        cmd.Parameters.AddWithValue("@MaxPrice", search.MaxPrice);
                    }
                    if (search.IsActive == null)
                    {
                        cmd.Parameters.AddWithValue("@IsActive", true);
                        cmd.Parameters.AddWithValue("@IsActiveCheck", false);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@IsActive", search.IsActive);
                        cmd.Parameters.AddWithValue("@IsActiveCheck", search.IsActive);
                    }

                    if (cnn.State == ConnectionState.Closed)
                    {
                        cnn.Open();
                    }
                    using (SqlDataReader sdr = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
                    {
                        if (await sdr.ReadAsync())
                        {
                            result = sdr.GetInt32(sdr.GetOrdinal("Total"));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }