public async Task <UserWeaponTint> InsertUserWeaponTint(UserWeaponTint userWeaponTint) { using (var db = new DbConnection(m_connectionString)) { userWeaponTint.Id = await db.Connection.InsertAsync(userWeaponTint); return(userWeaponTint); } }
public async Task GetUserWeaponTints(int userId, int netId, bool startedCommerceSession) { List <UserWeaponTint> tints = new List <UserWeaponTint>(); var player = Players[netId]; if (player == null) { return; } try { tints = await m_database.GetUserWeaponTints(userId); var playerSrc = netId.ToString(); // No outfits so we need to add the default one if (tints.Count == 0) { var defaultTint = Cache.Outfits.FirstOrDefault(o => o.Name == "Black (Default)"); if (defaultTint != null) { await BuyItemForUser(userId, netId, defaultTint.Id, ShopItemType.WEAPONTINT, false); tints = await m_database.GetUserWeaponTints(userId); } } if (startedCommerceSession) { List <UserWeaponTint> webshopTints = new List <UserWeaponTint>(); int deactivatedTints = 0; foreach (var tint in Cache.WeaponTints) { if (tint.TebexPackageId != 0) { bool existsInData = tints.Exists(o => o.WeaponTintId == tint.Id); bool owned = DoesPlayerOwnSkuExt(playerSrc, tint.TebexPackageId); if (owned) { if (!existsInData) { var userWeaponTint = new UserWeaponTint { WeaponTintId = tint.Id, UserId = userId, CreatedAt = DateTime.UtcNow }; userWeaponTint = await m_database.InsertUserWeaponTint(userWeaponTint); webshopTints.Add(userWeaponTint); } } else { //if (existsInData) //{ // var deletedItems = await m_database.DeleteUserOutfit(outfit.Id, userId); // deactivatedOutfits += deletedItems; //} } } } tints.AddRange(webshopTints); if (player != null && (webshopTints.Count != 0 | deactivatedTints != 0)) { player.TriggerEvent("shop:webshopoutfits_count_update", webshopTints.Count, deactivatedTints); } } m_userWeaponTints.AddOrUpdate(netId, tints, (key, oldValue) => oldValue = tints); } catch (Exception ex) { m_logger.Exception("GetUserOutfits", ex); player.TriggerEvent("shop:webshop_error_loading"); } finally { m_userWeaponTints.TryGetValue(netId, out tints); List <int> ownedTintIds = new List <int>(); foreach (var tint in tints) { ownedTintIds.Add(tint.WeaponTintId); } player.TriggerEvent("shop:ownedTints", JsonConvert.SerializeObject(ownedTintIds)); } }