Skip to content
This repository was archived by the owner on Oct 3, 2022. It is now read-only.

Commit 125209d

Browse files
committed
Further work on project types
1 parent 60d06d3 commit 125209d

File tree

7 files changed

+137
-22
lines changed

7 files changed

+137
-22
lines changed
506 Bytes
Binary file not shown.

.vs/TakeMyTime.NETCore/v16/.suo

0 Bytes
Binary file not shown.

TakeMyTime.BLL/Logic/ProjectTypeLogic.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ public void AddProjectType(ProjectType.ICreateParam param)
3939
unitOfWork.Complete();
4040
}
4141

42+
public void UpdateProjectType(int id, ProjectType.IUpdateParam param)
43+
{
44+
var projectType = this.unitOfWork.ProjectTypes.Get(id);
45+
projectType.Update(param);
46+
unitOfWork.Complete();
47+
}
48+
49+
public void DeleteProjectType(int id)
50+
{
51+
var projectType = this.unitOfWork.ProjectTypes.Get(id);
52+
if (projectType.CanDelete())
53+
{
54+
this.unitOfWork.ProjectTypes.Remove(projectType);
55+
this.unitOfWork.Complete();
56+
}
57+
else
58+
{
59+
throw new Exception("Cannot delete project type used in existing projects");
60+
}
61+
}
62+
4263
public void Dispose()
4364
{
4465
this.unitOfWork.Dispose();

TakeMyTime.Models/Models/ProjectType.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public interface ICreateParam
2121
string Description { get; set; }
2222
}
2323

24+
public interface IUpdateParam : ICreateParam
25+
{
26+
}
27+
2428
public void Init(string name, string description)
2529
{
2630
this.Name = name;
@@ -29,13 +33,18 @@ public void Init(string name, string description)
2933
this.SetCreated();
3034
}
3135

32-
public void Update(string name, string description)
36+
public void Update(ICreateParam param)
3337
{
34-
this.Name = name;
35-
this.Description = description;
38+
this.Name = param.Name;
39+
this.Description = param.Description;
3640
this.SetEdited();
3741
}
3842

43+
public bool CanDelete()
44+
{
45+
return this.Projects != null && this.Projects.Count == 0;
46+
}
47+
3948
public void AddProject(Project project)
4049
{
4150
if (this.Projects == null) this.Projects = new HashSet<Project>();
@@ -51,6 +60,6 @@ public void RemoveProject(Project project)
5160
}
5261

5362
public virtual string Description { get; set; }
54-
public virtual ICollection<Project> Projects { get; set; }
63+
public ICollection<Project> Projects { get; set; }
5564
}
5665
}

TakeMyTime.WPF/ProjectTypes/ProjectTypeOverview.xaml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,38 @@
1919
<Border Grid.Row="0">
2020
<StackPanel HorizontalAlignment="Right"
2121
Orientation="Horizontal">
22-
<Button Margin="5"
22+
<Button x:Name="btn_AddProjectType"
23+
Click="btn_AddProjectType_Click"
24+
Margin="5"
2325
Background="Green"
2426
ToolTip="{x:Static resource:ProjectTypeOverview.TooltipAddButton}">
2527
<materialDesign:PackIcon Kind="Plus"></materialDesign:PackIcon>
2628
</Button>
27-
<Button Margin="5"
29+
<Button x:Name="btn_EditProjectType"
30+
Click="btn_EditProjectType_Click"
31+
IsEnabled="False"
32+
Margin="5"
2833
Background="Orange"
2934
ToolTip="{x:Static resource:ProjectTypeOverview.TooltipEditButton}">
3035
<materialDesign:PackIcon Kind="Edit"></materialDesign:PackIcon>
3136
</Button>
32-
<Button Margin="5"
37+
<Button x:Name="btn_DeleteProjectType"
38+
Click="btn_DeleteProjectType_Click"
39+
IsEnabled="False"
40+
Margin="5"
3341
Background="Red"
3442
ToolTip="{x:Static resource:ProjectTypeOverview.TooltipDeleteButton}">
3543
<materialDesign:PackIcon Kind="Trash"></materialDesign:PackIcon>
3644
</Button>
3745
</StackPanel>
3846
</Border>
39-
<ScrollViewer Grid.Row="1">
40-
<DataGrid Grid.Row="1" Foreground="{StaticResource LightWhite}" Background="{StaticResource BackgroundGrey}"
47+
<DataGrid x:Name="dg_ProjectTypes" SelectionChanged="dg_ProjectTypes_SelectionChanged"
48+
Grid.Row="1" Foreground="{StaticResource LightWhite}" Background="{StaticResource BackgroundGrey}"
4149
CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False">
42-
<DataGrid.Columns>
50+
<DataGrid.Columns>
4351
<DataGridTextColumn Header="{x:Static resource:ProjectTypeOverview.ColumnName}" Width="300"></DataGridTextColumn>
44-
<DataGridTextColumn Header="{x:Static resource:ProjectTypeOverview.ColumnDescription}" Width="500"></DataGridTextColumn>
52+
<DataGridTextColumn Header="{x:Static resource:ProjectTypeOverview.ColumnDescription}" Width="500"></DataGridTextColumn>
4553
</DataGrid.Columns>
46-
</DataGrid>
47-
</ScrollViewer>
54+
</DataGrid>
4855
</Grid>
4956
</Page>
Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Text;
4-
using System.Windows;
3+
using System.Linq;
54
using System.Windows.Controls;
6-
using System.Windows.Data;
7-
using System.Windows.Documents;
8-
using System.Windows.Input;
9-
using System.Windows.Media;
10-
using System.Windows.Media.Imaging;
11-
using System.Windows.Navigation;
12-
using System.Windows.Shapes;
5+
using TakeMyTime.BLL.Logic;
136

147
namespace TakeMyTime.WPF.ProjectTypes
158
{
@@ -21,6 +14,70 @@ public partial class ProjectTypeOverview : Page
2114
public ProjectTypeOverview()
2215
{
2316
InitializeComponent();
17+
this.Load();
18+
this.RefreshBindings();
2419
}
20+
21+
private void Load()
22+
{
23+
var projectTypeLogic = new ProjectTypeLogic();
24+
this.ProjectTypeViewModels = projectTypeLogic.GetProjectTypes().Select(pt => new ProjectTypeViewModel(pt)).ToList();
25+
}
26+
27+
private void RefreshBindings()
28+
{
29+
this.dg_ProjectTypes.ItemsSource = this.ProjectTypeViewModels;
30+
}
31+
32+
#region GUI Events
33+
34+
private void dg_ProjectTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
35+
{
36+
bool selectionNotNull = e.AddedItems != null && e.AddedItems.Count > 0;
37+
btn_EditProjectType.IsEnabled = selectionNotNull;
38+
btn_DeleteProjectType.IsEnabled = selectionNotNull;
39+
if (selectionNotNull)
40+
{
41+
this.SelectedProjectType = e.AddedItems[0] as ProjectTypeViewModel;
42+
}
43+
else
44+
{
45+
this.SelectedProjectType = null;
46+
}
47+
}
48+
49+
private void btn_AddProjectType_Click(object sender, System.Windows.RoutedEventArgs e)
50+
{
51+
52+
}
53+
54+
private void btn_EditProjectType_Click(object sender, System.Windows.RoutedEventArgs e)
55+
{
56+
57+
}
58+
59+
private void btn_DeleteProjectType_Click(object sender, System.Windows.RoutedEventArgs e)
60+
{
61+
if (this.SelectedProjectType != null)
62+
{
63+
var projectTypeLogic = new ProjectTypeLogic();
64+
projectTypeLogic.DeleteProjectType(this.SelectedProjectType.Id);
65+
this.SelectedProjectType = null;
66+
this.Load();
67+
this.RefreshBindings();
68+
}
69+
}
70+
71+
#endregion
72+
73+
#region Properties
74+
75+
public IEnumerable<ProjectTypeViewModel> ProjectTypeViewModels { get; set; }
76+
public ProjectTypeViewModel SelectedProjectType { get; set; }
77+
78+
79+
#endregion
80+
81+
2582
}
2683
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using TakeMyTime.Models.Models;
5+
6+
namespace TakeMyTime.WPF.ProjectTypes
7+
{
8+
public class ProjectTypeViewModel
9+
{
10+
public ProjectTypeViewModel(ProjectType projectType)
11+
{
12+
this.Id = projectType.Id;
13+
this.Name = projectType.Name;
14+
this.Description = projectType.Description;
15+
}
16+
17+
public int Id { get; set; }
18+
public string Name { get; set; }
19+
public string Description { get; set; }
20+
}
21+
}

0 commit comments

Comments
 (0)