public ActionResult IndexPost(LocationFilterViewModel model)
 {
     // This is a hack used to keep a clean URL.
     // If the form is of FormMethod.Get it will send all fields as query string, this is default behavior
     // However by using POST and redirecting to the GET action you push the values through MVC routing, which filters out null values
     return(RedirectToAction("Index", "Locations", model));
 }
        public IActionResult LocationGet(ResultsFilter filter)
        {
            var viewModel = new LocationFilterViewModel
            {
                FilterModel = filter
            };
            var errors = TempData.Get <ErrorViewModel>("Errors");

            if (errors != null && errors.AppliesToUrl(Url.Action("Location")))
            {
                viewModel.Errors = errors;
            }

            return(View("Location", viewModel));
        }
        public IActionResult LocationGet(ResultsFilter filter)
        {
            if (_featureFlags.RedirectToRailsPageLocation)
            {
                return(_redirectUrlService.RedirectToNewApp());
            }

            var viewModel = new LocationFilterViewModel
            {
                FilterModel = filter
            };
            var errors = TempData.Get <ErrorViewModel>("Errors");

            if (errors != null && errors.AppliesToUrl(Url.Action("Location")))
            {
                viewModel.Errors = errors;
            }

            return(View("Location", viewModel));
        }
        public GenericCollectionViewModel <ListLocationsLightViewModel> GetByFilter(LocationFilterViewModel model)
        {
            var lang = this._languageService.CurrentLanguage;
            ConditionFilter <Location, long> condition = new ConditionFilter <Location, long>()
            {
                Order = Order.Descending
            };

            if (model.Sort?.Count > 0)
            {
                if (model.Sort[0].Dir != "desc")
                {
                    condition.Order = Order.Ascending;
                }
            }

            //if (model.DateFrom.HasValue) model.DateFrom = model.DateFrom.SetTimeToNow();
            if (model.DateTo.HasValue)
            {
                model.DateTo = model.DateTo.SetTimeToMax();
            }

            // The IQueryable data to query.
            IQueryable <Location> queryableData = this._LocationsRepository.Get(condition);

            queryableData = queryableData.Where(x => x.Language == lang && x.ParentKeyLocationId.HasValue == true);

            if (string.IsNullOrEmpty(model.Code) == false)
            {
                queryableData = queryableData.Where(x => x.ParentKeyLocation.Code.Contains(model.Code));
            }

            if (string.IsNullOrEmpty(model.Title) == false)
            {
                queryableData = queryableData.Where(x => x.ParentKeyLocation.Title.Contains(model.Title));
            }

            if (model.DateFrom.HasValue)
            {
                queryableData = queryableData.Where(x => x.ParentKeyLocation.Date >= model.DateFrom);
            }

            if (model.DateTo.HasValue)
            {
                queryableData = queryableData.Where(x => x.ParentKeyLocation.Date <= model.DateTo);
            }


            var entityCollection = queryableData.ToList();
            var dtoCollection    = entityCollection.Select(entity => entity.ToListModel()).ToList();

            //foreach (var item in entityCollection)
            //{
            //    var ViewModel = dtoCollection.Find(x => x.Id == item.Id);

            //    //if (item.ParentKeyBank != null)
            //    //{
            //    //    ViewModel.BankName = item.ParentKeyBank.ChildTranslatedBanks.First(x => x.Language == lang).Name;
            //    //}
            //}

            //if (model.Filters != null)
            //{
            //    foreach (var item in model.Filters)
            //    {
            //        switch (item.Field)
            //        {
            //            case "source":
            //                dtoCollection = dtoCollection.Where(x => x.Source.Contains(item.Value)).ToList();
            //                break;
            //            case "amount":
            //                dtoCollection = dtoCollection.Where(x => x.Amount.Equals(Convert.ToDecimal(item.Value))).ToList();
            //                break;
            //            default:
            //                break;
            //        }
            //    }
            //}
            var total = dtoCollection.Count();

            dtoCollection = dtoCollection.Skip(model.PageIndex * model.PageSize).Take(model.PageSize).ToList();
            var result = new GenericCollectionViewModel <ListLocationsLightViewModel>
            {
                Collection = dtoCollection,
                TotalCount = total,
                PageIndex  = model.PageIndex,
                PageSize   = model.PageSize
            };

            return(result);
        }
        public async Task <ActionResult> Index(LocationFilterViewModel model = null, int page = 1)
        {
            int itemsPerPage = 10;

            if (page < 1)
            {
                page = 1;
            }

            IPagedList <DbLocation> pagedLocations = null;
            LocationFilter          filter         = new LocationFilter();

            try
            {
                var locationsRepository = _unitOfWork.LocationsRepository;
                if (model == null)
                {
                    pagedLocations = locationsRepository.GetAllPaged(page, itemsPerPage);
                }
                else
                {
                    filter.Name           = model.Name;
                    filter.CityOrPostcode = model.CityOrPostcode;
                    filter.From           = model.From;
                    filter.MinCapacity    = model.MinCapacity;
                    filter.Province       = model.Province;
                    filter.To             = model.To;
                    pagedLocations        = locationsRepository.GetAllPagedWithFilter(page, itemsPerPage, filter);
                }
                ViewBag.PagedLocations = pagedLocations;
            }
            catch
            {
                TempData["AlertType"]    = "danger";
                TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het ophalen van de locaties";
            }

            // If there are no results, we try to get some from our partners
            ViewBag.PagedThirdPartyLocations = new List <ThirdPartyLocationOverviewViewModel>();
            if (pagedLocations.TotalItemCount == 0)
            {
                List <ThirdPartyLocationOverviewViewModel> thirdPartyLocations = new List <ThirdPartyLocationOverviewViewModel>();

                ApiClient apiClient = new ApiClient();
                try
                {
                    // Tim
                    string urlTim = GenerateUrlWithFilter("http://jeugdlocatie.timvettori.ikdoeict.net/Api/SharedLocations/", filter, cityOrPostCodeParamName: "location", fromParamName: "startDateTime", toParamName: "endDateTime");
                    IEnumerable <ApiLocationTim> locationsTim = await apiClient.Request <IEnumerable <ApiLocationTim> >(urlTim);

                    IEnumerable <ThirdPartyLocationOverviewViewModel> mappedLocationsTim = locationsTim.Select(x =>
                    {
                        return(x.ToViewModel());
                    });
                    thirdPartyLocations.AddRange(mappedLocationsTim);
                }
                catch
                {
                    // This ensures graceful failure when Tim's API fails
                    // In production we would log this exceptions
                }

                try
                {
                    // Diede
                    string urlDiede = GenerateUrlWithFilter("http://diedeseldeslachts.ikdoeict.net/api/LocationSearchAPI/Get", filter, cityOrPostCodeParamName: "cityOrPostcode", fromParamName: "startDateTime", toParamName: "endDateTime");
                    IEnumerable <ApiLocationDiede> locationsDiede = await apiClient.Request <IEnumerable <ApiLocationDiede> >(urlDiede);

                    IEnumerable <ThirdPartyLocationOverviewViewModel> mappedLocationsDiede = locationsDiede.Select(x =>
                    {
                        return(x.ToViewModel());
                    });
                    thirdPartyLocations.AddRange(mappedLocationsDiede);
                }
                catch
                {
                    // This ensures graceful failure when Diede's API fails
                    // In production we would log this exceptions
                }

                ViewBag.PagedThirdPartyLocations = thirdPartyLocations.ToPagedList(page, itemsPerPage);
            }

            model.Page = page;
            return(View(model));
        }