public ViewResult Add()
        {
            var sports = _sportManager.SportsList();
            var addSportEventViewModel = new AddSportEventViewModel
            {
                Sports = sports
            };

            return(View(addSportEventViewModel));
        }
Beispiel #2
0
        public IActionResult GetSport([FromQuery] int offset = 0, [FromQuery] int limit = 10, [FromQuery] string name = "")
        {
            var sports = _sportManager.SportsList().Where(b => b.Name.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) != -1).Skip(offset).Take(limit);

            var sportMapped = _mapper.Map <IEnumerable <SportDTO> >(sports).Select(s => new HALResponse(s).AddLinks(s.GetLinks()));

            return(Ok(new HALResponse(null).AddLinks(new[] {
                new Link("self", "/api/sports", null, "GET")
            }).AddEmbeddedCollection("sports", sportMapped)));;
        }
        public ViewResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var sports = _iSportManager.SportsList();

            if (!string.IsNullOrEmpty(searchString))
            {
                sports = sports.Where(s => s.Name.ToLower().Contains(searchString.ToLower()));
            }


            switch (sortOrder)
            {
            case "name_desc":
                sports = sports.OrderByDescending(s => s.Name).ToList();
                break;

            default:
                sports = sports.OrderBy(s => s.Name).ToList();
                break;
            }

            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(sports.AsQueryable().ToPagedList(pageNumber, pageSize)));
        }