private void DeleteMembre(string membreId) { foreach (MemberTrait ma in KTContext.Db.MemberTraits.Where(m => m.MemberId == membreId).AsNoTracking().ToList()) { MemberTrait mad = KTContext.Db.MemberTraits.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPower ma in KTContext.Db.MemberPowers.Where(m => m.MembrerId == membreId).AsNoTracking().ToList()) { MemberPower mad = KTContext.Db.MemberPowers.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWeapon ma in KTContext.Db.MemberWeapons.Where(m => m.MemberId == membreId).AsNoTracking().ToList()) { MemberWeapon mad = KTContext.Db.MemberWeapons.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPsychic ma in KTContext.Db.MemberPsychics.Where(m => m.MemberId == membreId).AsNoTracking().ToList()) { MemberPsychic mad = KTContext.Db.MemberPsychics.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWarGearOption ma in KTContext.Db.MemberWarGearOptions.Where(m => m.MemberId == membreId).AsNoTracking().ToList()) { MemberWarGearOption mad = KTContext.Db.MemberWarGearOptions.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } var membre = KTContext.Db.Members.Find(membreId); KTContext.Db.Entry(membre).State = EntityState.Deleted; KTContext.Db.SaveChanges(); OnAppearing(); }
public void Handle(DeleteTeamCommand command) { var teamId = command.TeamId; foreach (MemberTrait ma in KTContext.Db.MemberTraits.Where(m => m.Member.TeamId == teamId).AsNoTracking().ToList()) { MemberTrait mad = KTContext.Db.MemberTraits.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPsychic ma in KTContext.Db.MemberPsychics.Where(m => m.Member.TeamId == teamId).AsNoTracking().ToList()) { MemberPsychic mad = KTContext.Db.MemberPsychics.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPower ma in KTContext.Db.MemberPowers.Where(m => m.Member.TeamId == teamId).AsNoTracking().ToList()) { MemberPower mad = KTContext.Db.MemberPowers.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWeapon ma in KTContext.Db.MemberWeapons.Where(m => m.Member.TeamId == teamId).AsNoTracking().ToList()) { MemberWeapon mad = KTContext.Db.MemberWeapons.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWarGearOption ma in KTContext.Db.MemberWarGearOptions.Where(m => m.Member.TeamId == teamId).AsNoTracking().ToList()) { MemberWarGearOption mad = KTContext.Db.MemberWarGearOptions.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (Member ma in KTContext.Db.Members.Where(m => m.TeamId == teamId).AsNoTracking().ToList()) { Member mad = KTContext.Db.Members.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } var team = KTContext.Db.Teams.Find(teamId); KTContext.Db.Set <Team>().Remove(team); KTContext.Db.SaveChanges(); }
async void ButtonSupprimerClicked(object sender, EventArgs e) { string NomEquipe = KTContext.Db.Teams.Where(eq => eq.Id == equipeId).Select(m => m.Name).First(); bool reponse = await DisplayAlert(Translate.Supprimer, Translate.EtesVousSur + " \"" + NomEquipe + "\" ?", Translate.Oui, Translate.Non); if (reponse) { foreach (MemberTrait ma in KTContext.Db.MemberTraits.Where(m => m.Member.TeamId == equipeId).AsNoTracking().ToList()) { MemberTrait mad = KTContext.Db.MemberTraits.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPsychic ma in KTContext.Db.MemberPsychics.Where(m => m.Member.TeamId == equipeId).AsNoTracking().ToList()) { MemberPsychic mad = KTContext.Db.MemberPsychics.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberPower ma in KTContext.Db.MemberPowers.Where(m => m.Member.TeamId == equipeId).AsNoTracking().ToList()) { MemberPower mad = KTContext.Db.MemberPowers.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWeapon ma in KTContext.Db.MemberWeapons.Where(m => m.Member.TeamId == equipeId).AsNoTracking().ToList()) { MemberWeapon mad = KTContext.Db.MemberWeapons.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (MemberWarGearOption ma in KTContext.Db.MemberWarGearOptions.Where(m => m.Member.TeamId == equipeId).AsNoTracking().ToList()) { MemberWarGearOption mad = KTContext.Db.MemberWarGearOptions.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } foreach (Member ma in KTContext.Db.Members.Where(m => m.TeamId == equipeId).AsNoTracking().ToList()) { Member mad = KTContext.Db.Members.Find(ma.Id); KTContext.Db.Entry(mad).State = EntityState.Deleted; } var equipe = KTContext.Db.Teams.Find(equipeId); KTContext.Db.Entry(equipe).State = EntityState.Deleted; KTContext.Db.SaveChanges(); await Navigation.PopAsync(); } }
public bool UpdateMembre() { if (isBusy) { return(false); } isBusy = true; PossibleSwap changementPossible = (PossibleSwap)BindingContext; //suppression des anciens remplacements var remplacements = KTContext.Db.MemberWarGearOptions.AsNoTracking().Where(m => m.MemberId == membreId).ToList(); foreach (MemberWarGearOption mr in remplacements) { MemberWarGearOption mr2 = KTContext.Db.MemberWarGearOptions.AsTracking().Where(aa => aa.Id == mr.Id).First(); KTContext.Db.Entry(mr2).State = EntityState.Deleted; } //Suppression des anciennes armes var armes = KTContext.Db.MemberWeapons.AsNoTracking().Where(m => m.MemberId == membreId).ToList(); foreach (MemberWeapon ma in armes) { MemberWeapon ma2 = KTContext.Db.MemberWeapons.AsTracking().Where(aa => aa.Id == ma.Id).First(); KTContext.Db.Entry(ma2).State = EntityState.Deleted; } //Ajout de la config foreach (WarGearCombination configuration in changementPossible.WarGearCombinations.Where(c => c.Selected)) { foreach (Weapon arme in configuration.Weapons) { MemberWeapon membreArme = new MemberWeapon(); membreArme.Id = Guid.NewGuid().ToString(); membreArme.WeaponId = arme.Id; membreArme.MemberId = membreId; KTContext.Db.Entry(membreArme).State = EntityState.Added; } foreach (WarGearOption remp in configuration.WarGearOption) { MemberWarGearOption membreRemplacement = new MemberWarGearOption(); membreRemplacement.Id = Guid.NewGuid().ToString(); membreRemplacement.WarGearOptionId = remp.Id; membreRemplacement.MemberId = membreId; KTContext.Db.Entry(membreRemplacement).State = EntityState.Added; } } //Ajout armes optionnelles foreach (WarGearCombination configuration in changementPossible.OptionalWeapons.Where(c => c.Selected)) { foreach (Weapon arme in configuration.Weapons) { MemberWeapon membreArme = new MemberWeapon(); membreArme.Id = Guid.NewGuid().ToString(); membreArme.WeaponId = arme.Id; membreArme.MemberId = membreId; KTContext.Db.Entry(membreArme).State = EntityState.Added; } foreach (WarGearOption remp in configuration.WarGearOption) { MemberWarGearOption membreRemplacement = new MemberWarGearOption(); membreRemplacement.Id = Guid.NewGuid().ToString(); membreRemplacement.WarGearOptionId = remp.Id; membreRemplacement.MemberId = membreId; KTContext.Db.Entry(membreRemplacement).State = EntityState.Added; } } //Ajout armes obligatoires foreach (Weapon arme in changementPossible.FixedWeapons) { MemberWeapon membreArme = new MemberWeapon(); membreArme.Id = Guid.NewGuid().ToString(); membreArme.WeaponId = arme.Id; membreArme.MemberId = membreId; KTContext.Db.Entry(membreArme).State = EntityState.Added; } KTContext.Db.SaveChanges(); Member membre = KTContext.Db.Members .Where(m => m.Id == membreId) .Include(m => m.ModelProfile.CostOverrides) .Include(m => m.ModelProfile.LevelCosts) .Include(m => m.MemberWeapons) .ThenInclude(m => m.Weapon) .Include(m => m.MemberTraits) .ThenInclude(m => m.Trait) .AsNoTracking() .First(); membre.UpdateCost(); Member mb = KTContext.Db.Members.Find(membre.Id); mb.Cost = membre.Cost; KTContext.Db.Entry(mb).State = EntityState.Modified; KTContext.Db.SaveChanges(); isBusy = false; return(true); }