public bool SaveClass(ClassDetailsDTO dto) { using (HugoLANDContext context = new HugoLANDContext()) { try { var currClass = new Classe() { Id = dto.Id, NomClasse = dto.ClassName, Description = dto.Description, StatBaseStr = dto.StatBaseStr, StatBaseDex = dto.StatBaseDex, StatBaseReg = dto.StatBaseReg, StatBaseVitalite = dto.StatBaseVitality, }; context.Entry(currClass).State = EntityState.Modified; context.SaveChanges(); return(true); } catch { return(false); } } }
public bool CreateClass(ClassDetailsDTO newClass, WorldDetailsDTO world) { try { using (HugoLANDContext context = new HugoLANDContext()) { Monde monde = context.Mondes.Find(world.ID); var classe = new Classe() { NomClasse = newClass.ClassName, Description = newClass.Description, StatBaseStr = newClass.StatBaseStr, StatBaseDex = newClass.StatBaseDex, StatBaseReg = newClass.StatBaseReg, StatBaseVitalite = newClass.StatBaseVitality, Monde = monde, }; context.Entry(classe).State = EntityState.Added; context.SaveChanges(); return(true); } } catch { return(false); } }
public bool CreateHero(HeroDetailsDTO dto) { try { using (var context = new HugoLANDContext()) { Monde monde = context.Mondes.First(m => m.Description == dto.World); Classe classe = context.Classes.First(c => c.NomClasse == dto.Class); CompteJoueur compteJoueur = context.CompteJoueurs.First(a => a.NomJoueur == dto.UserName); var hero = new Hero { Niveau = 1, Experience = 0, x = 0, y = 0, StatStr = dto.StatStr, StatDex = dto.StatDex, StatReg = dto.StatReg, StatVitalite = dto.StatVitality, NomHero = dto.HeroName, EstConnecte = false, Classe = classe, CompteJoueur = compteJoueur, Monde = monde }; context.Entry(hero).State = EntityState.Added; context.SaveChanges(); } return(true); } catch { return(false); } }
public bool DeleteClass(ClassDetailsDTO dto) { try { using (HugoLANDContext context = new HugoLANDContext()) { var delClass = context.Classes.Find(dto.Id); List <int> listDelHero = new List <int>(); List <int> listDelHeroItems = new List <int>(); List <int> listDelHeroInventaire = new List <int>(); foreach (Hero hero in delClass.Heros) { listDelHero.Add(hero.Id); foreach (Item item in hero.Items) { listDelHeroItems.Add(item.Id); } foreach (InventaireHero inv in hero.InventaireHeroes) { listDelHeroInventaire.Add(inv.IdInventaireHero); } } foreach (int id in listDelHeroItems) { context.Entry(context.Items.Find(id)).State = EntityState.Deleted; } foreach (int id in listDelHeroInventaire) { context.Entry(context.InventaireHeroes.Find(id)).State = EntityState.Deleted; } foreach (int id in listDelHero) { context.Entry(context.Heros.Find(id)).State = EntityState.Deleted; } context.Entry(delClass).State = EntityState.Deleted; context.SaveChanges(); return(true); } } catch { return(false); } }
public bool DeleteHero(HeroDetailsDTO dto) { try { using (var context = new HugoLANDContext()) { var hero = context.Heros.Find(dto.Id); context.Entry(hero).State = EntityState.Deleted; context.SaveChanges(); } return(true); } catch { return(false); } }