public static Item GetItemByID(int id) { PlayerDBModel con = new PlayerDBModel(); Item temp = (from item in con.Items where item.ItemID == id select item).ToList()[0]; return(temp); }
/*************************************************************************************/ /**************************************************************************************/ // Read /**************************************************************/ // Player public static List <Player> LoadAllPlayers() { PlayerDBModel context = new PlayerDBModel(); List <Player> pList = context.Players.ToList(); return(pList); }
/**************************************************************/ // Item public static Item GetItemByName(string n) { PlayerDBModel con = new PlayerDBModel(); List <Item> itemList = (from Item in con.Items where Item.ItemName == n orderby Item.ItemID descending select Item).ToList(); return(itemList.First()); }
public static List <Item> GetAllItems() { PlayerDBModel con = new PlayerDBModel(); List <Item> itemList = (from Item in con.Items where Item.ItemID > 0 orderby Item.ItemID descending select Item).ToList(); return(itemList); }
/**************************************************************/ // Inventory public static List <Inventory> GetItemFromPlayerInventory(Player p, Item i) { using (PlayerDBModel con = new PlayerDBModel()) { if (p != null && i != null) { return(con.Inventories.Where(x => x.PlayerID == p.PlayerID).ToList().Where(y => y.ItemID == i.ItemID).ToList()); } } return(null); }
public static void AddItemToInventory(Player pPlayer, Item pItem) { var con = new PlayerDBModel(); try { con.Inventories.Add(new Inventory(pPlayer, pItem)); con.SaveChanges(); } catch (Exception ex) { } }
public static void AddItem(Item i) { PlayerDBModel con = new PlayerDBModel(); try { con.Items.Add(i); con.SaveChanges(); } catch // Not doing anything with exception atm { } }
/*************************************************************************************/ /**************************************************************************************/ // Update public static void UpdateItem(Item pItem) { if (checkItemIsValid(pItem)) { var con = new PlayerDBModel(); Item fromDB = con.Items.Find(pItem.ItemID); fromDB.ItemName = pItem.ItemName; fromDB.ItemDesc = pItem.ItemDesc; con.SaveChanges(); } }
/**************************************************************************************/ // Create public static void AddPlayer(Player p) { PlayerDBModel context = new PlayerDBModel(); try { // Add Player to DB context.Players.Add(p); // Save Changes. context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/*************************************************************************************/ /**************************************************************************************/ // Delete public static void DeleteItemFromPlayerInventory(Player p, Item i) { if (p != null && i != null) { using (PlayerDBModel con = new PlayerDBModel()) { var iList = GetItemFromPlayerInventory(p, i); if (iList.Count > 0) { var temp = iList.First(); con.Inventories.Add(temp); con.Entry <Inventory>(temp).State = System.Data.Entity.EntityState.Deleted; con.SaveChanges(); } } } }
public static List <Inventory> GetPlayerInventory(Player pPlayer) { PlayerDBModel con = new PlayerDBModel(); return((from Item in con.Inventories where (Item.PlayerID == pPlayer.PlayerID) select Item).ToList()); }