Example #1
0
        public ViewResult MatchesList(int?page = 1)
        {
            ViewBag.Title = "Matches List";
            MatchesListViewModel MListed = new MatchesListViewModel();

            MListed.GetAllPlayers          = _allPlayers.AllPlayers;
            MListed.GetAllMatches          = _allMatches.AllMatches;
            MListed.GetAllMatchParticipant = _allMatchParticipant.AllMatchParticipant;
            MListed.GetAllMatches          = MListed.GetAllMatches.OrderByDescending(m => m.Time);


            var count = 0;

            foreach (Match match in MListed.GetAllMatches)
            {
                count++;
            }
            var pagesCount = (count / 10) + 1;

            ViewBag.PagesCount    = pagesCount;
            ViewBag.Page          = page;
            MListed.GetAllMatches = MListed.GetAllMatches.Skip((Convert.ToInt32(page) - 1) * 10).Take(10);
            //MListed.GetAllMatches = MListed.GetAllMatches.Take(10);
            return(View(MListed));
        }
Example #2
0
        // GET: Matches
        public ActionResult Index([FromUri] int skip = 0, [FromUri] int take = 10, [FromUri] string search = null, [FromUri] bool?pastUnfinished = null)
        {
            if (pastUnfinished.HasValue && pastUnfinished.Value && !AuthorizeExtensions.CurrentUserIsAdmin())
            {
                throw new UnauthorizedAccessException();
            }

            MatchesListViewModel model = new MatchesListViewModel();

            var searchQueryParam = string.Empty;

            if (!string.IsNullOrEmpty(search))
            {
                searchQueryParam         = $"&search={search}";
                ViewData["SearchString"] = search;
            }

            var pastUnfinishedQueryParam = string.Empty;

            if (pastUnfinished.HasValue)
            {
                pastUnfinishedQueryParam   = $"&pastUnfinished={pastUnfinished.Value}";
                ViewData["PastUnfinished"] = pastUnfinished.Value;
            }

            model.Items = webClient.ExecuteGet <IEnumerable <MatchDto> >(new Models.ApiRequest()
            {
                EndPoint = $"matches?skip={skip}&take={take}{searchQueryParam}{pastUnfinishedQueryParam}"
            })
                          ?.Select(q => new MatchesListItem()
            {
                Id          = q.Id,
                Boxer1Id    = q.Boxer1Id,
                Boxer2Id    = q.Boxer2Id,
                Boxer1      = new BoxersListItem(q.Boxer1.Name),
                Boxer2      = new BoxersListItem(q.Boxer2.Name),
                Address     = q.Address,
                Time        = q.Time,
                Description = q.Description,
                WinnerId    = q.WinnerId
            })?.ToList();

            var currentUser   = AuthorizeExtensions.GetCurrentUser();
            var currentUserId = currentUser != null ? currentUser.Id : 0;

            var predictions = webClient.ExecuteGet <IEnumerable <PredictionDto> >(new Models.ApiRequest()
            {
                EndPoint = "predictions"
            })
                              ?.Select(q => new PredictionsListItem()
            {
                Id = q.Id,
                PredictedBoxerId = q.PredictedBoxerId,
                MatchId          = q.MatchId,
                UserId           = q.UserId
            })?.Where(p => p.UserId == currentUserId)?.ToList();

            ViewData["Predictions"] = predictions;
            ViewData["Page"]        = (skip / take) + 1;
            ViewData["PageSize"]    = take;
            return(View(model));
        }