public Equipment GetOne(int id) { using (var context = new NinjaStoreDbContext()) { return(context.Equipment.FirstOrDefault(e => e.EquipmentId == id)); } }
public Ninja GetOne(int id) { using (var context = new NinjaStoreDbContext()) { return(context.Ninjas.FirstOrDefault(n => n.NinjaId == id)); } }
public List <Equipment> GetAll() { using (var context = new NinjaStoreDbContext()) { return(context.Equipment.ToList()); } }
public List <Ninja> GetAll() { using (var context = new NinjaStoreDbContext()) { return(context.Ninjas.ToList()); } }
public void Create(Equipment equipment) { using (var context = new NinjaStoreDbContext()) { context.Equipment.Add(equipment); context.SaveChanges(); } }
public void Create(Ninja ninja) { using (var context = new NinjaStoreDbContext()) { context.Ninjas.Add(ninja); context.SaveChanges(); } }
public void Update(Equipment equipment) { using (var context = new NinjaStoreDbContext()) { context.Attach(equipment); context.Equipment.Update(equipment); context.SaveChanges(); } }
public void Update(Ninja ninja) { using (var context = new NinjaStoreDbContext()) { context.Attach(ninja); context.Ninjas.Update(ninja); context.SaveChanges(); } }
public List <Equipment> ShowEquipment(int ninjaId) { using (var context = new NinjaStoreDbContext()) { var ninjaIncludingItems = context.Ninjas.Include(ninja => ninja.Bevat).ThenInclude(e => e.Equipment).First(n => n.NinjaId == ninjaId); var ninjaItems = ninjaIncludingItems.Bevat.Select(e => e.Equipment); return(ninjaItems.ToList()); } }
public bool Delete(int id) { using (var context = new NinjaStoreDbContext()) { var toRemove = context.Equipment.Find(id); if (toRemove != null) { context.Equipment.Remove(toRemove); context.SaveChanges(); return(true); } return(false); } }
public List <Equipment> buyAbleEquipment(int ninjaId, Category category) { using (var context = new NinjaStoreDbContext()) { IEnumerable <Equipment> result; if (category == null) { result = context.Equipment.ToList().Where(n => ShowEquipment(ninjaId).All(n2 => n2.EquipmentId != n.EquipmentId)); } result = context.Equipment.ToList().Where(n => ShowEquipment(ninjaId).All(n2 => n2.EquipmentId != n.EquipmentId)).Where(e => e.Category.Equals(category)); return(result.ToList()); } }
public bool SellEquipment(int ninjaId, int equipmentId) { using (var context = new NinjaStoreDbContext()) { var ninja = context.Ninjas.FirstOrDefault(n => n.NinjaId == ninjaId); var equipment = context.Equipment.FirstOrDefault(e => e.EquipmentId == equipmentId); ninja.Gold = ninja.Gold + equipment.Value; NinjaEquipment ninjaEquipment = new NinjaEquipment { Ninja = ninja, Equipment = equipment, NinjaId = ninjaId, EquipmentId = equipmentId }; context.Attach(ninja); context.Ninjas.Update(ninja); context.NinjaEquipment.Remove(ninjaEquipment); context.SaveChanges(); return(true); } }