@ -13,11 +13,21 @@ namespace Gremlin.MVVM
{
{
public class ShellViewModel : PropertyChangedBase
public class ShellViewModel : PropertyChangedBase
{
{
//public AllContactsViewModel AllContactsVM { get; set; }
private ContactViewModel _selectedContact ;
private ContactViewModel _selectedContact ;
private ObservableCollection < ContactViewModel > _contacts ;
private ObservableCollection < ContactViewModel > _contacts ;
private QuoteViewModel _quoteVM ;
private QuoteViewModel _quoteVM ;
private string _searchContact ;
public string SearchContact
{
get = > _searchContact ;
set
{
_searchContact = value ;
NotifyOfPropertyChange ( ( ) = > SearchContact ) ;
Contacts = GetContactsVM ( _searchContact ) ;
}
}
public QuoteViewModel QuoteVM
public QuoteViewModel QuoteVM
{
{
@ -55,16 +65,19 @@ namespace Gremlin.MVVM
{
{
//AllContactsVM = new();
//AllContactsVM = new();
QuoteVM = new ( ) ;
QuoteVM = new ( ) ;
Contacts = Get All ContactsVM( ) ;
Contacts = Get ContactsVM( "" ) ;
}
}
internal static ObservableCollection < ContactViewModel > Get All ContactsVM( )
internal static ObservableCollection < ContactViewModel > Get ContactsVM( string searchContact )
{
{
try
try
{
{
using ( GremlinContext gremlinContext = new ( ) )
using ( GremlinContext gremlinContext = new ( ) )
{
{
List < Contact > contacts = gremlinContext . Contacts . Include ( contact = > contact . Account ) . ToList ( ) ;
List < Contact > contacts = searchContact is "" or null
? gremlinContext . Contacts . Include ( contact = > contact . Account ) . ToList ( )
: gremlinContext . Contacts . Where ( contact = > contact . LastName . Contains ( searchContact ) ) . Include ( contact = > contact . Account ) . ToList ( ) ;
ObservableCollection < ContactViewModel > contactsVM = new ( ) ;
ObservableCollection < ContactViewModel > contactsVM = new ( ) ;
foreach ( Contact contact in contacts )
foreach ( Contact contact in contacts )