private void UpdateNinja() { using (var context = new NinjaEntities()) { var ninja = NinjaVM.ToModel(); context.Entry(ninja).State = EntityState.Modified; context.SaveChanges(); } _ninjaListVM.HideUpdateNinja(); }
private void SellEverything() { foreach (EquipmentVM e in EquipmentInventoryOC) { NinjaVM.Money += e.EquipmentValue; } using (var context = new NinjaEntities()) { context.InventoryItems.Where(p => p.NinjaId == NinjaVM.NinjaId).ToList().ForEach(p => context.InventoryItems.Remove(p)); var ninja = NinjaVM.ToModel(); context.Entry(ninja).State = EntityState.Modified; context.SaveChanges(); } EquipmentInventoryOC.Clear(); }
private void BuyItem() { if (SelectedEquipment != null && NinjaVM.Money > SelectedEquipment.EquipmentValue) { var InventoryItemVM = new InventoryVM(); var inventoryItem = InventoryItemVM.ToModel(); inventoryItem.NinjaId = NinjaVM.NinjaId; inventoryItem.IsUsingEquitment = false; inventoryItem.EquipmentId = SelectedEquipment.EquipmentId; _inventoryListVM.EquipmentInventoryOC.Add(SelectedEquipment); using (var context = new NinjaEntities()) { EquipmentVM items = new EquipmentVM(context.Equipments.Where(e => e.EquipmentId == inventoryItem.EquipmentId).First()); NinjaVM.Money -= items.EquipmentValue; var ninja = NinjaVM.ToModel(); context.Entry(ninja).State = EntityState.Modified; context.InventoryItems.Add(inventoryItem); context.Entry(inventoryItem).State = EntityState.Added; context.SaveChanges(); } this.RaisePropertyChanged(); ShopItemsOC.Remove(SelectedEquipment); } }