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);
        }
示例#2
0
 public async Task <bool> Update(ServerSelectedMap serverSelectedMap)
 {
     return(await _liteDb.LiteDatabaseAsync.GetCollection <ServerSelectedMap>("ServerSelectedMap")
            .UpdateAsync(serverSelectedMap));
 }
示例#3
0
 public async Task <int> Insert(ServerSelectedMap serverSelectedMap)
 {
     return(await _liteDb.LiteDatabaseAsync.GetCollection <ServerSelectedMap>("ServerSelectedMap")
            .InsertAsync(serverSelectedMap));
 }