コード例 #1
0
ファイル: GameData.cs プロジェクト: DaVinci-98/PBgra
        /// <summary>
        /// Saves a room object.
        /// </summary>
        /// <param name="room">
        /// Room object to save.
        /// </param>
        /// <returns>
        /// Id of room saved.
        /// </returns>
        /// Saves only room data.
        public async Task <int> Save(RoomModel room)
        {
            //save operation is perforemd in transaction
            _gameDataAccess.StartTransaction();

            var model = new Room
            {
                Level    = room.Level,
                RoomID   = room.Id,
                Seen     = room.Seen ? 1 : 0,
                RoomType = room.Type,
                TTL      = room.TTL
            };

            //saves type of effect of enchantement available to buy in room
            if (room.ShopEvent?.BuyableEnchantement != null)
            {
                model.EffectType = room.ShopEvent.BuyableEnchantement.Type;
            }

            //check if room already exists
            var exists = await _gameDataAccess.Get(model);

            if (exists == null)
            {
                //if not add it and fetch it's id
                int id = await _gameDataAccess.Add(model);

                _gameDataAccess.Save();
                return(id);
            }
            else
            {
                await _gameDataAccess.Update(model);

                _gameDataAccess.Save();
                return(model.RoomID.Value);
            }
        }