// opérations CRUD... public void CreatePersonne(DTO.Personne Personne) { using (MesDepensesContext context = new MesDepensesContext()) { try { context.Personnes.Add(Personne); context.SaveChanges(); } catch { throw; } } }
public void DeletePersonne(DTO.Personne Personne) { using (MesDepensesContext context = new MesDepensesContext()) try { context.Personnes.Attach(Personne); context.Personnes.Remove(Personne); context.SaveChanges(); } catch { throw; } }
public void UpdatePersonne(DTO.Personne Personne, DTO.Personne PersonneUpdated) { using (MesDepensesContext context = new MesDepensesContext()) try { if (Personne != null && PersonneUpdated != null) { PersonneUpdated.PersonneID = Personne.PersonneID; context.Entry(Personne).CurrentValues.SetValues(Personne); } } catch { throw; } }
public MainWindowViewModel() { var MesDepensesManager = new MesDepensesManagerModel(); DTO.Personne myPersonne = new DTO.Personne("Bobby", "Jones"); DTO.Depense depenseBobby = new DTO.Depense(20, "restaurant"); // DTO.Piece chambreCyprien = new DTO.Piece("chambreCyprien7", 12); myPersonne.Depenses.Add(depenseBobby); //myHotel.Pieces.Add(chambreCyprien); MesDepensesManager.CreatePersonne(myPersonne); // DTO.Hotel myHotel2 = new DTO.Hotel("googleHotel7"); // DTO.Piece chambreTimothe = new DTO.Piece("chambreTimothe7", 12); // myHotel2.Pieces.Add(chambreTimothe); // hotelManager.CreateHotel(myHotel2); List <DTO.Personne> listPersonnes = MesDepensesManager.DisplayAllPersonnes(); Personnes = CollectionViewSource.GetDefaultView(listPersonnes); }