public async Task DeleteEvent(EventList eventList) { using var context = new RPGContext(_options); context.Remove(eventList); await context.SaveChangesAsync().ConfigureAwait(false); }
public bool Equip(Item item) { bool success = false; using (RPGContext context = new RPGContext()) { if (this.PlayerItem.Item.Type != ItemType.None) { Unequip(); } context.PlayerItems.Remove(this.PlayerItem); context.Items.Remove(this.PlayerItem.Item); bool inRoom = this.Room.Inventory.Items.Exists(x => x.ItemId == item.ItemId); bool inPlayerInventory = this.Inventory.Items.Exists(x => x.ItemId == item.ItemId); if (inRoom || inPlayerInventory) { Inventory inventory; if (inRoom) { inventory = this.Room.Inventory; } else { inventory = this.Inventory; } InventoryItem inventoryItem = inventory.Items.Find(x => x.ItemId == item.ItemId); inventory.Items.Remove(inventoryItem); context.Remove(inventoryItem); context.Update(inventory); } else { //the item is not somewhere that can be picked up and/or equipped } PlayerItem playerItem = new PlayerItem { PlayerItemId = Guid.NewGuid(), Player = this, Item = item }; context.PlayerItems.Add(playerItem); context.SaveChanges(); } return(success); }
public async Task <bool> RemoveItemAsync(string itemName) { using var context = new RPGContext(_options); var item = await GetItemByNameAsync(itemName).ConfigureAwait(false); context.Remove(item); await context.SaveChangesAsync().ConfigureAwait(false); return(true); }
public async Task DeleteStatChannel(ulong guildId, StatOption stat) { using var context = new RPGContext(_options); GuildPreferences guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(guildId); CheckForGuildsStatCatergoryChannel(guildPrefs); var channelStat = guildPrefs.StatChannels.Where(x => x.StatOption == stat).FirstOrDefault(); if (channelStat == null) { return; } context.Remove(channelStat); await context.SaveChangesAsync(); }