Ejemplo n.º 1
0
        public async Task <ActionResult> Index(string searchName,
                                               string searchLabelId,
                                               string searchAddress,
                                               string searchCity,
                                               string searchRouteSelection,
                                               string sortField         = "RestroomName",
                                               string sortDirection     = "Ascending",
                                               int page                 = 1,
                                               string statusId          = "All",
                                               string showPublic        = "All",
                                               string showToilet        = "All",
                                               string showPendingReview = "All")
        {
            var restroomViewModel = new RestroomViewModel();

            try
            {
                //Persit information for next page load
                Session["SearchName"]        = searchName;
                Session["SearchLabelId"]     = searchLabelId;
                Session["SearchAddress"]     = searchAddress;
                Session["SearchCity"]        = searchCity;
                Session["SearchRoutes"]      = searchRouteSelection;
                Session["SortField"]         = sortField ?? "RestroomName";
                Session["StatusId"]          = statusId;
                Session["ShowPublic"]        = showPublic;
                Session["showToilet"]        = showToilet;
                Session["ShowPendingReview"] = showPendingReview;
                Session["SortDirection"]     = sortDirection ?? "Ascending";
                Session["Page"] = page;

                using (var service = new RestroomService())
                {
                    restroomViewModel.ApprovedRestrooms = await service.GetApprovedRestroomsAsync(new RestroomSearchContext
                    {
                        Name          = searchName,
                        LabelId       = searchLabelId,
                        Address       = searchAddress,
                        City          = searchCity,
                        Routes        = string.IsNullOrEmpty(searchRouteSelection) ? null : searchRouteSelection.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                        Public        = showPublic == "All" ? (bool?)null : showPublic == "True",
                        StatusId      = statusId == "All" ? (int?)null : int.Parse(statusId),
                        HasToilet     = showToilet == "All" ? (bool?)null : showToilet == "True",
                        PendingReview = showPendingReview == "All" ? (bool?)null : showPendingReview == "True",
                        SortField     = sortField,
                        SortDirection = sortDirection.Equals("Ascending", StringComparison.CurrentCultureIgnoreCase)
                                            ? System.Web.Helpers.SortDirection.Ascending
                                            : System.Web.Helpers.SortDirection.Descending,
                        PageNumber = page
                    });

                    restroomViewModel.ToiletGenders = service.GetToiletGenders();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError("ACTransit.RestroomFinder.Web.RestroomController.Index", ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            return(View(restroomViewModel));
        }