EventAggrigationProvider added to handle events between windows/usercontrols, persons can be added now

This commit is contained in:
2020-05-17 21:23:45 +02:00
parent 94056f5f08
commit 8ae6337c00
5 changed files with 67 additions and 11 deletions

View File

@ -50,6 +50,12 @@ namespace TrackerWPFUI.ViewModels
} }
} }
public void CancelCreation()
{
EventAggregationProvider.TrackerEventAggregator.PublishOnUIThread(new PersonModel());
this.TryClose();
}
public bool CanCreatePerson(string firstName, string lastName, string email, string cellphone) public bool CanCreatePerson(string firstName, string lastName, string email, string cellphone)
{ {
if(firstName.Length>0 && lastName.Length>0 && email.Length>0 && cellphone.Length > 0) if(firstName.Length>0 && lastName.Length>0 && email.Length>0 && cellphone.Length > 0)
@ -74,6 +80,9 @@ namespace TrackerWPFUI.ViewModels
GlobalConfig.Connection.CreatePerson(p); GlobalConfig.Connection.CreatePerson(p);
//TODO - Send results back to parent and close //TODO - Send results back to parent and close
EventAggregationProvider.TrackerEventAggregator.PublishOnUIThread(p);
this.TryClose();
} }
} }
} }

View File

@ -9,17 +9,21 @@ using TrackerLibrary.Models;
namespace TrackerWPFUI.ViewModels namespace TrackerWPFUI.ViewModels
{ {
public class CreateTeamViewModel : Conductor<object> public class CreateTeamViewModel : Conductor<object>, IHandle<PersonModel>
{ {
private string _teamName = ""; private string _teamName = "";
private BindableCollection<PersonModel> _availableTeamMembers; private BindableCollection<PersonModel> _availableTeamMembers;
private PersonModel _selectedTeamMemberToAdd; private PersonModel _selectedTeamMemberToAdd;
private BindableCollection<PersonModel> _selectedTeamMembers = new BindableCollection<PersonModel>(); private BindableCollection<PersonModel> _selectedTeamMembers = new BindableCollection<PersonModel>();
private PersonModel _selectedTeamMemberToRemove; private PersonModel _selectedTeamMemberToRemove;
private bool _selectedTeamMembersIsVisible = true;
private bool _addPersonIsVisible = false;
public CreateTeamViewModel() public CreateTeamViewModel()
{ {
AvailableTeamMembers = new BindableCollection<PersonModel>(GlobalConfig.Connection.GetPerson_All()); AvailableTeamMembers = new BindableCollection<PersonModel>(GlobalConfig.Connection.GetPerson_All());
EventAggregationProvider.TrackerEventAggregator.Subscribe(this);
} }
@ -34,6 +38,26 @@ namespace TrackerWPFUI.ViewModels
} }
} }
public bool SelectedTeamMembersIsVisible
{
get { return _selectedTeamMembersIsVisible; }
set
{
_selectedTeamMembersIsVisible = value;
NotifyOfPropertyChange(() => SelectedTeamMembersIsVisible);
}
}
public bool AddPersonIsVisible
{
get { return _addPersonIsVisible; }
set
{
_addPersonIsVisible = value;
NotifyOfPropertyChange(() => AddPersonIsVisible);
}
}
public BindableCollection<PersonModel> AvailableTeamMembers public BindableCollection<PersonModel> AvailableTeamMembers
{ {
get { return _availableTeamMembers; } get { return _availableTeamMembers; }
@ -74,7 +98,7 @@ namespace TrackerWPFUI.ViewModels
public void AddMember() public void AddMember()
{ {
SelectedTeamMembers.Add(SelectedTeamMemberToAdd); SelectedTeamMembers.Add(SelectedTeamMemberToAdd);
AvailableTeamMembers.Remove(SelectedTeamMemberToAdd ); AvailableTeamMembers.Remove(SelectedTeamMemberToAdd);
NotifyOfPropertyChange(() => CanCreateTeam); NotifyOfPropertyChange(() => CanCreateTeam);
} }
public PersonModel SelectedTeamMemberToRemove public PersonModel SelectedTeamMemberToRemove
@ -105,7 +129,9 @@ namespace TrackerWPFUI.ViewModels
public void CreateMember() public void CreateMember()
{ {
ActivateItem(new CreatePersonViewModel());
SelectedTeamMembersIsVisible = false;
AddPersonIsVisible = true;
} }
public bool CanCreateTeam public bool CanCreateTeam
{ {
@ -140,6 +166,17 @@ namespace TrackerWPFUI.ViewModels
//TODO - Pass the team back to the parent and close the form //TODO - Pass the team back to the parent and close the form
} }
public void Handle(PersonModel message)
{
if (!string.IsNullOrWhiteSpace(message.FullName))
{
SelectedTeamMembers.Add(message);
NotifyOfPropertyChange(() => CanCreateTeam);
}
SelectedTeamMembersIsVisible = true;
AddPersonIsVisible = false;
} }
}
} }

View File

@ -18,8 +18,8 @@ namespace TrackerWPFUI.ViewModels
GlobalConfig.InitializeConnections(DatabaseType.Sql); GlobalConfig.InitializeConnections(DatabaseType.Sql);
_existingTournaments = new BindableCollection<TournamentModel>(GlobalConfig.Connection.GetTournament_All()); _existingTournaments = new BindableCollection<TournamentModel>(GlobalConfig.Connection.GetTournament_All());
//ActivateItem(new CreatePrizeViewModel()); //ActivateItem(new CreatePrizeViewModel());
//ActivateItem(new CreateTeamViewModel()); ActivateItem(new CreateTeamViewModel());
ActivateItem(new CreatePersonViewModel()); //ActivateItem(new CreatePersonViewModel());
} }
public void CreateTournament() public void CreateTournament()
{ {

View File

@ -37,9 +37,14 @@
<TextBlock Margin="5 0 10 10" Grid.Column="0" Grid.Row="3">Cellphone</TextBlock> <TextBlock Margin="5 0 10 10" Grid.Column="0" Grid.Row="3">Cellphone</TextBlock>
<TextBox x:Name="Cellphone" Margin="0 0 5 10" Grid.Column="2" Grid.Row="3"></TextBox> <TextBox x:Name="Cellphone" Margin="0 0 5 10" Grid.Column="2" Grid.Row="3"></TextBox>
<!--row 4--> <!--row 4-->
<Button x:Name="CreatePerson" Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" Padding="10" Margin="5 0 "> <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" Margin="5 0 " HorizontalAlignment="Center">
<Button x:Name="CreatePerson" Padding="10" Margin="0 0 5 0">
Create Person Create Person
</Button> </Button>
<Button x:Name="CancelCreation" Padding="10" Background="Red" Foreground="White" Margin="5 0 0 0">
Cancel Person
</Button>
</StackPanel >
</Grid> </Grid>
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -20,10 +20,15 @@
<Button x:Name="CreateMember" Padding="5" >Create Member</Button> <Button x:Name="CreateMember" Padding="5" >Create Member</Button>
<Button x:Name="RemoveMember" Padding="5" Margin="5 0 0 0">Remove Member</Button> <Button x:Name="RemoveMember" Padding="5" Margin="5 0 0 0">Remove Member</Button>
</StackPanel> </StackPanel>
<TextBlock Margin="5 0 5 10" >Selected Team Members</TextBlock> <StackPanel x:Name="SelectedTeamMembersIsVisible" Orientation="Vertical" Margin="5 10 5 0">
<TextBlock Margin="0 0 0 10" >Selected Team Members</TextBlock>
<ListBox x:Name="SelectedTeamMembers" DisplayMemberPath="FullName" <ListBox x:Name="SelectedTeamMembers" DisplayMemberPath="FullName"
Margin="5 0 5 0" MinHeight="20" MinHeight="20"
SelectedItem="{Binding Path=SelectedTeamMemberToRemove, Mode=TwoWay}" /> SelectedItem="{Binding Path=SelectedTeamMemberToRemove, Mode=TwoWay}" />
</StackPanel>
<StackPanel x:Name="AddPersonIsVisible" Orientation="Vertical" Margin="5 10 5 0">
<ContentControl x:Name="ActiveItem"/>
</StackPanel>
<Button x:Name="CreateTeam" Margin="5 10 5 5" Padding="5" >Create Team</Button> <Button x:Name="CreateTeam" Margin="5 10 5 5" Padding="5" >Create Team</Button>
</StackPanel> </StackPanel>
</Grid> </Grid>