Пример #1
0
        public async Task <IActionResult> Index(int?teamId, int?playerRoleId, int?battingStyleId, int?bowlingStyleId, string name, int?userId, int?page)
        {
            var users = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.Name         = "Players";
            ViewBag.PlayerRoleId = new SelectList(_context.PlayerRole
                                                  .AsNoTracking()
                                                  .Select(i => new { i.Name, i.PlayerRoleId }), "PlayerRoleId", "Name");

            ViewBag.BattingStyleId = new SelectList(_context.BattingStyle
                                                    .AsNoTracking()
                                                    .Select(i => new { i.Name, i.BattingStyleId }), "BattingStyleId", "Name");

            ViewBag.BowlingStyleId = new SelectList(_context.BowlingStyle
                                                    .AsNoTracking()
                                                    .Select(i => new { i.Name, i.BowlingStyleId }), "BowlingStyleId", "Name");
            if (users != null)
            {
                userId = users.Id;
            }


            ViewBag.TeamId = new SelectList(_context.Teams
                                            .AsNoTracking()
                                            .Where(i => (!userId.HasValue || i.clubAdmin.UserId == userId))
                                            .Select(i => new { i.TeamId, i.Team_Name })
                                            , "TeamId", "Team_Name");
            var model = await _players.GetAllPlayersList(teamId, playerRoleId, battingStyleId, bowlingStyleId, name, userId, page);

            return(View(model));
        }
        // [HttpGet("Players/Index/teamId/{teamId}/playerRoleId/{playerRoleId}/battingStyleId/{battingStyleId}/bowlingStyleId/{bowlingStyleId}/name/{name}/isApi/{isApi}")]
        public async Task <IActionResult> Index(DataTableAjaxPostModel model, int?teamId, int?playerRoleId, int?battingStyleId, int?bowlingStyleId, string name, bool isApi)
        {
            var users = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.Name   = "Players";
            ViewBag.Season = new SelectList(_context.Matches
                                            .Select(i => i.Season)
                                            .ToList().Distinct(), "Season");

            ViewBag.MatchType    = new SelectList(_context.MatchType, "MatchTypeId", "MatchTypeName");
            ViewBag.PlayerRoleId = new SelectList(_context.PlayerRole
                                                  .AsNoTracking()
                                                  .Select(i => new { i.Name, i.PlayerRoleId }), "PlayerRoleId", "Name");

            ViewBag.BattingStyleId = new SelectList(_context.BattingStyle
                                                    .AsNoTracking()
                                                    .Select(i => new { i.Name, i.BattingStyleId }), "BattingStyleId", "Name");

            ViewBag.BowlingStyleId = new SelectList(_context.BowlingStyle
                                                    .AsNoTracking()
                                                    .Select(i => new { i.Name, i.BowlingStyleId }), "BowlingStyleId", "Name");



            ViewBag.TeamId = new SelectList(_context.Teams
                                            .AsNoTracking()
                                            .Select(i => new { i.TeamId, i.Team_Name })
                                            , "TeamId", "Team_Name");
            var result = await _players.GetAllPlayersList(model.Init(), teamId, playerRoleId, battingStyleId, bowlingStyleId, name);

            if (isApi == true)
            {
                return(Json(new
                {
                    data = result,
                    draw = model.Draw,
                    recordsTotal = result.TotalCount,
                    recordsFiltered = result.TotalCount,
                }));
            }
            else
            {
                return(View(result));
            }
        }