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(); } }
private void UpdateDatabase() { var traits = BindingContext as List <ListTraitViewModel>; var membre = KTContext.Db.Members.AsNoTracking().Where(m => m.Id == membreId).Include(m => m.ModelProfile.Traits).Include(m => m.MemberTraits).ThenInclude(mt => mt.Trait).First(); foreach (MemberTrait mt in membre.MemberTraits) { var membreTrait = KTContext.Db.MemberTraits.AsTracking().Where(m => m.Id == mt.Id).First(); KTContext.Db.Entry(membreTrait).State = EntityState.Deleted; } foreach (var t in traits.Where(t => t.Selected)) { MemberTrait membreTrait = new MemberTrait { Id = Guid.NewGuid().ToString(), MemberId = membreId, TraitId = t.Trait.Id }; KTContext.Db.Entry(membreTrait).State = EntityState.Added; } if (!traits.Any(t => t.Selected && t.Trait.Id == "G5")) { var membrePouvoir = KTContext.Db.MemberPowers.AsTracking().Where(m => m.IsGeneral).FirstOrDefault(); if (membrePouvoir != null) { KTContext.Db.Entry(membrePouvoir).State = EntityState.Deleted; } } if (!traits.Any(t => t.Selected && t.Trait.Id == "G6")) { var membrePouvoir = KTContext.Db.MemberPowers.AsTracking().Where(m => m.IsMaster).FirstOrDefault(); if (membrePouvoir != null) { KTContext.Db.Entry(membrePouvoir).State = EntityState.Deleted; } } KTContext.Db.SaveChanges(); Member trackedMembre = KTContext.Db.Members.AsNoTracking().Where(m => m.Id == membreId) .Where(m => m.Id == membreId) .Include(m => m.MemberPowers) .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) .First(); trackedMembre.UpdateCost(); Member mb = KTContext.Db.Members.Find(membre.Id); mb.Cost = trackedMembre.Cost; KTContext.Db.Entry(mb).State = EntityState.Modified; KTContext.Db.SaveChanges(); Title = trackedMembre.Title; }