public void InsertNinja() { //inicializa a injeção de dependencia //SimpleInjectorContainer.RegisterServices(); INinjaRepository ninjaRepository = new NinjaRepository(); INinjaClanRepository ninjaClanRepository = new NinjaClanRepository(); var ninjaClan = ninjaClanRepository.FindBy(nc => nc.ClanName == "Camargo's").FirstOrDefault(); if (ninjaClan != null) { Ninja ninja = new Ninja { NinjaName = "Bruna", DateCreated = DateTime.Now, DateModified = DateTime.Now, NinjaClanId = ninjaClan.Id }; if (!ninjaRepository.FindBy(n => n.NinjaName == ninja.NinjaName).Any()) { ninjaRepository.Add(ninja); ninjaRepository.Save(); } } }
public IActionResult BuyArmour([FromRoute] int id, int ninjaId) { if (id <= 0) { return(NotFound()); } var selectedNinja = _ninjaRepository.GetDetailed(ninjaId); var justBoughtArmour = _armourRepository.Get(id); var equippedArmour = selectedNinja.EquippedArmour.Select(na => na.Armour); // Dispose of detailed relations to prevent issues when deleting related data selectedNinja = _ninjaRepository.Get(ninjaId); foreach (var armour in equippedArmour) { // Check if ninja already has this armour type if (armour.ArmourType != justBoughtArmour.ArmourType) { continue; } // Sell old armour DeleteNinjaArmour(ninjaId, armour.Id); break; } _ninjaArmourRepository.Add(new NinjaArmour { ArmourId = justBoughtArmour.Id, NinjaId = selectedNinja.Id }); selectedNinja.Gold -= justBoughtArmour.Price; _ninjaRepository.Update(selectedNinja); _ninjaArmourRepository.Save(); _ninjaRepository.Save(); return(RedirectToAction(nameof(Index), new { ninjaId = ninjaId })); }
public override IActionResult DeleteConfirmed(int id) { var ninjaHasArmour = _ninjaArmourRepository.GetNinjaFromArmour(id); var armourValue = _armourRepository.Get(id).Price; foreach (var ninja in ninjaHasArmour) { ninja.Gold += armourValue; _ninjaRepository.Update(ninja); } _ninjaRepository.Save(); return(base.DeleteConfirmed(id)); }
public void UpdateNinjaAndClan() { var ninjaRepository = new NinjaRepository(); var ninjaClanRepository = new NinjaClanRepository(); var ninja = ninjaRepository.GetById(1); var ninjaClan = ninjaClanRepository.GetById(ninja.NinjaClanId); ninja.NinjaName = "Murilo Cesar"; ninjaRepository.Update(ninja); ninjaRepository.Save(); ninjaClan.ClanName = "Gafanhotos"; ninjaClanRepository.Update(ninjaClan); ninjaClanRepository.Save(); }
public void InsertNinjaWithoutClan() { //inicializa a injeção de dependencia SimpleInjectorContainer.RegisterServices(); INinjaRepository ninjaRepository = new NinjaRepository(); Ninja ninja = new Ninja { NinjaName = "Bolacha", DateCreated = DateTime.Now, DateModified = DateTime.Now }; if (!ninjaRepository.FindBy(n => n.NinjaName == ninja.NinjaName).Any()) { ninjaRepository.Add(ninja); ninjaRepository.Save(); } }