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)
{
if(firstName.Length>0 && lastName.Length>0 && email.Length>0 && cellphone.Length > 0)
@ -74,6 +80,9 @@ namespace TrackerWPFUI.ViewModels
GlobalConfig.Connection.CreatePerson(p);
//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
{
public class CreateTeamViewModel : Conductor<object>
public class CreateTeamViewModel : Conductor<object>, IHandle<PersonModel>
{
private string _teamName = "";
private BindableCollection<PersonModel> _availableTeamMembers;
private PersonModel _selectedTeamMemberToAdd;
private BindableCollection<PersonModel> _selectedTeamMembers = new BindableCollection<PersonModel>();
private PersonModel _selectedTeamMemberToRemove;
private bool _selectedTeamMembersIsVisible = true;
private bool _addPersonIsVisible = false;
public CreateTeamViewModel()
{
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
{
get { return _availableTeamMembers; }
@ -105,7 +129,9 @@ namespace TrackerWPFUI.ViewModels
public void CreateMember()
{
ActivateItem(new CreatePersonViewModel());
SelectedTeamMembersIsVisible = false;
AddPersonIsVisible = true;
}
public bool CanCreateTeam
{
@ -140,6 +166,17 @@ namespace TrackerWPFUI.ViewModels
//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);
_existingTournaments = new BindableCollection<TournamentModel>(GlobalConfig.Connection.GetTournament_All());
//ActivateItem(new CreatePrizeViewModel());
//ActivateItem(new CreateTeamViewModel());
ActivateItem(new CreatePersonViewModel());
ActivateItem(new CreateTeamViewModel());
//ActivateItem(new CreatePersonViewModel());
}
public void CreateTournament()
{

View File

@ -37,9 +37,14 @@
<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>
<!--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
</Button>
<Button x:Name="CancelCreation" Padding="10" Background="Red" Foreground="White" Margin="5 0 0 0">
Cancel Person
</Button>
</StackPanel >
</Grid>
</StackPanel>
</Grid>

View File

@ -20,10 +20,15 @@
<Button x:Name="CreateMember" Padding="5" >Create Member</Button>
<Button x:Name="RemoveMember" Padding="5" Margin="5 0 0 0">Remove Member</Button>
</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"
Margin="5 0 5 0" MinHeight="20"
MinHeight="20"
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>
</StackPanel>
</Grid>