public async Task <bool> SaveServerSelectedMap(int serverId, string mapId, string gameMode, bool move = true, [CanBeNull] string oldMode = "")
        {
            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), serverId, _service, _pavlovServerService))
            {
                return(false);
            }
            var realMap = await _mapsService.FindOne(mapId);

            var pavlovServer = await _pavlovServerService.FindOne(serverId);

            var mapsSelected = await _serverSelectedMapService.FindAllFrom(pavlovServer);

            if (mapsSelected != null)
            {
                var toUpdate = mapsSelected.FirstOrDefault(x => x.Map?.Id == realMap.Id && x.GameMode == gameMode);
                if (toUpdate == null)
                {
                    var newMap = new ServerSelectedMap
                    {
                        Map          = realMap,
                        PavlovServer = pavlovServer,
                        GameMode     = gameMode
                    };
                    await _serverSelectedMapService.Insert(newMap);

                    if (!move) // means that it just changed GameMode
                    {
                        //i need to know to old Game Mode
                        var oldMap = mapsSelected.FirstOrDefault(x => x.Map?.Id == realMap.Id && x.GameMode == oldMode);
                        if (oldMap != null)
                        {
                            await _serverSelectedMapService.Delete(oldMap.Id);
                        }
                    }
                }
                else
                {
                    //Can never go here?
                    toUpdate.GameMode = gameMode;
                    await _serverSelectedMapService.Update(toUpdate);
                }
            }
            else
            {
                var newMap = new ServerSelectedMap
                {
                    GameMode     = gameMode,
                    Map          = realMap,
                    PavlovServer = pavlovServer
                };
                await _serverSelectedMapService.Insert(newMap);
            }

            return(true);
        }
        public void FindOne()
        {
            // arrange
            InsertMap(_mapsService);
            // act
            var map = _mapsService.FindOne("1").GetAwaiter().GetResult();

            // assert
            map.Should().NotBe(null);
            map.Name.Should().Be("test");
        }
        public async Task <IActionResult> EditMatchResult(int id)
        {
            var user = await _userservice.getUserFromCp(HttpContext.User);

            var servers = await _matchService.FindAllMatchesWhereTheUserHasRights(HttpContext.User, user);

            if (!servers.Select(x => x.Id).Contains(id))
            {
                return(Forbid());
            }

            var match = await _matchService.FindOne(id);

            if (match == null)
            {
                return(BadRequest("No match like that exists!"));
            }
            if (!match.isFinished())
            {
                return(BadRequest("Match is not finished jet!"));
            }
            if (match.EndInfo == null)
            {
                return(BadRequest("Match has no endInfo"));
            }
            var map = await _mapsService.FindOne(match.MapId.Replace("UGC", ""));

            if (map == null)
            {
                return(BadRequest("Match has no map set"));
            }
            var result = _publicViewListsService.PavlovServerPlayerListPublicViewModel(new PavlovServerInfo
            {
                MapLabel       = match.MapId,
                MapPictureLink = map.ImageUrl,
                GameMode       = match.EndInfo.GameMode,
                ServerName     = match.EndInfo.ServerName,
                RoundState     = match.EndInfo.RoundState,
                PlayerCount    = match.EndInfo.PlayerCount,
                Teams          = match.EndInfo.Teams,
                Team0Score     = match.EndInfo.Team0Score,
                Team1Score     = match.EndInfo.Team1Score,
                ServerId       = match.PavlovServer.Id
            }, match.PlayerResults);

            result.MatchId = match.Id;
            return(View("EditResult", result));
        }
        // GET
        public async Task <IActionResult> PlayersFromMatches([FromQuery] int[] matchIds,
                                                             [FromQuery] string backgroundColorHex, [FromQuery] string fontColorHex)
        {
            var result = new List <PavlovServerPlayerListPublicViewModel>();

            foreach (var matchId in matchIds)
            {
                var match = await _matchService.FindOne(matchId);

                if (match == null)
                {
                    continue;
                }
                if (!match.hasStats())
                {
                    continue;
                }
                var map = await _mapsService.FindOne(match.MapId.Replace("UGC", ""));

                if (map == null)
                {
                    continue;
                }
                result.Add(_publicViewListsService.PavlovServerPlayerListPublicViewModel(new PavlovServerInfo
                {
                    MapLabel       = match.MapId,
                    MapPictureLink = map.ImageUrl,
                    GameMode       = match.EndInfo.GameMode,
                    ServerName     = match.EndInfo.ServerName,
                    RoundState     = match.EndInfo.RoundState,
                    PlayerCount    = match.EndInfo.PlayerCount,
                    Teams          = match.EndInfo.Teams,
                    Team0Score     = match.EndInfo.Team0Score,
                    Team1Score     = match.EndInfo.Team1Score,
                    ServerId       = match.PavlovServer.Id
                }, match.PlayerResults));
            }

            ViewBag.background = backgroundColorHex;
            ViewBag.textColor  = fontColorHex;
            return(PartialView("PlayersFromServers", result));
        }