Skip to content

Commit

Permalink
#234 fix missing strategy instance
Browse files Browse the repository at this point in the history
  • Loading branch information
AnhAnNek committed May 17, 2023
1 parent f22aba4 commit ab37d71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ private void SetVisibilityViewEmployees()

private void InitDeptStrategy()
{
IDeptStrategy strategy = new DeptForDeptHead();
try
{
var curEmpl = CurrentUser.Ins.Empl;
var deptStrategy = DeptStrategyFactory.Create(curEmpl.EmplRole.Perms);
var viewModel = new DepartmentsViewModel(deptStrategy)
{
ParentDataContext = this
};
departmentsView.DataContext = viewModel;
strategy = DeptStrategyFactory.Create(curEmpl.EmplRole.Perms);
}
catch (Exception ex)
{
Log.Ins.Error(nameof(OrganizationViewModel), ex.Message);
}
var viewModel = new DepartmentsViewModel(strategy)
{
ParentDataContext = this
};
departmentsView.DataContext = viewModel;
}

private void SetCommand()
Expand Down
9 changes: 5 additions & 4 deletions CompanyManagement/ViewModels/Windows/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ private void ExecuteLoginCommand(Window window)

private void ShowMainWindow(EPermission perms)
{
IMainStrategy strategy = new MainForEmployee();
try
{
var mainStrategy = MainStrategyFactory.Create(perms);
var viewModel = new MainViewModel(mainStrategy);
var nextWindow = new MainWindow { DataContext = viewModel };
nextWindow.ShowDialog();
strategy = MainStrategyFactory.Create(perms);
}
catch (Exception ex)
{
Log.Ins.Error(nameof(LoginViewModel), ex.Message);
}
var viewModel = new MainViewModel(strategy);
var nextWindow = new MainWindow { DataContext = viewModel };
nextWindow.ShowDialog();
}

private void RefreshAllText()
Expand Down
5 changes: 3 additions & 2 deletions CompanyManagement/Views/UserControls/ProjectsUC.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ public partial class ProjectsUC : UserControl
public ProjectsUC()
{
InitializeComponent();
IProjectsStrategy strategy = new ProjectsForEmployee();
try
{
var curEmpl = CurrentUser.Ins.Empl;
var projectsStrategy = ProjectsStrategyFactory.Create(curEmpl.EmplRole.Perms);
DataContext = new ProjectsViewModel(projectsStrategy);
strategy = ProjectsStrategyFactory.Create(curEmpl.EmplRole.Perms);
}
catch (Exception ex)
{
Log.Ins.Error(nameof(ProjectsUC), ex.Message);
}
DataContext = new ProjectsViewModel(strategy);
}
}
}

0 comments on commit ab37d71

Please sign in to comment.