Skip to content

Commit b7bf9d0

Browse files
committed
update example application
1 parent e0a5431 commit b7bf9d0

30 files changed

+872
-255
lines changed

Example.BusinessApp.Infrastructure/Example.BusinessApp.Infrastructure.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@
8787
<DesignTimeSharedInput>True</DesignTimeSharedInput>
8888
</Compile>
8989
<Compile Include="InfrastructureAutofacModule.cs" />
90+
<Compile Include="Screens\EditScreenBase.cs" />
91+
<Compile Include="Screens\ScreenBase.cs" />
9092
<Compile Include="Services\CustomerService.cs" />
9193
<Compile Include="Services\ICustomerService.cs" />
94+
<Compile Include="Services\IRoleService.cs" />
9295
<Compile Include="Services\IUserService.cs" />
96+
<Compile Include="Models\Role.cs" />
97+
<Compile Include="Services\RoleService.cs" />
98+
<Compile Include="Services\SaveResult.cs" />
9399
<Compile Include="Services\UserService.cs" />
94100
<Compile Include="ViewModels\ConfirmViewModel.cs" />
95101
<Compile Include="ViewModels\StartUpViewModel.cs" />
@@ -122,6 +128,10 @@
122128
</Page>
123129
</ItemGroup>
124130
<ItemGroup>
131+
<ProjectReference Include="..\Matisco.Domain\Matisco.Domain.csproj">
132+
<Project>{2B8C7E70-4BB7-4959-8E06-78C021379DA2}</Project>
133+
<Name>Matisco.Domain</Name>
134+
</ProjectReference>
125135
<ProjectReference Include="..\Matisco.Wpf.Controls\Matisco.Wpf.Controls.csproj">
126136
<Project>{ccd09ed5-5267-4d08-9328-3e86487ca8d8}</Project>
127137
<Name>Matisco.Wpf.Controls</Name>

Example.BusinessApp.Infrastructure/InfrastructureAutofacModule.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protected override void Load(ContainerBuilder builder)
1010
{
1111
builder.RegisterType<UserService>().As<IUserService>().SingleInstance();
1212
builder.RegisterType<CustomerService>().As<ICustomerService>().SingleInstance();
13+
builder.RegisterType<RoleService>().As<IRoleService>().SingleInstance();
1314
}
1415
}
1516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Example.BusinessApp.Infrastructure.Models
2+
{
3+
public class Role
4+
{
5+
public int Id { get; set; }
6+
7+
public string Description { get; set; }
8+
9+
public Role Clone()
10+
{
11+
return new Role()
12+
{
13+
Id = Id,
14+
Description = Description
15+
};
16+
}
17+
}
18+
}

Example.BusinessApp.Infrastructure/Models/User.cs

+20
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,25 @@ public class User
77
public string Email { get; set; }
88

99
public int Id { get; set; }
10+
11+
public bool IsCool { get; set; }
12+
13+
public bool? IsCoolNullable { get; set; }
14+
15+
public double Length { get; set; }
16+
17+
public int BirthYear { get; set; }
18+
19+
public decimal NetValue { get; set; }
20+
21+
public User Clone()
22+
{
23+
return new User()
24+
{
25+
Id = Id,
26+
Name = Name,
27+
Email = Email
28+
};
29+
}
1030
}
1131
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System.Windows.Input;
2+
using Matisco.Wpf.Controls.Buttons;
3+
using Matisco.Wpf.Interfaces;
4+
using Prism.Commands;
5+
using Prism.Mvvm;
6+
using Prism.Regions;
7+
8+
namespace Example.BusinessApp.Infrastructure.Screens
9+
{
10+
public abstract class EditScreenBase : ScreenBase, INavigationAware, IEditor
11+
{
12+
private bool _editMode;
13+
private string _editSaveMessage;
14+
private string _cancelCloseMessage;
15+
private ButtonImageEnum _editSaveButtonImage;
16+
private ButtonImageEnum _cancelCloseButtonImage;
17+
18+
public bool EditMode
19+
{
20+
get { return _editMode; }
21+
set
22+
{
23+
_editMode = value;
24+
OnPropertyChanged();
25+
}
26+
}
27+
28+
public string EditSaveMessage
29+
{
30+
get { return _editSaveMessage; }
31+
set
32+
{
33+
_editSaveMessage = value;
34+
OnPropertyChanged();
35+
}
36+
}
37+
38+
public string CancelCloseMessage
39+
{
40+
get { return _cancelCloseMessage; }
41+
set
42+
{
43+
_cancelCloseMessage = value;
44+
OnPropertyChanged();
45+
}
46+
}
47+
48+
public ButtonImageEnum EditSaveButtonImage
49+
{
50+
get { return _editSaveButtonImage; }
51+
set
52+
{
53+
_editSaveButtonImage = value;
54+
OnPropertyChanged();
55+
}
56+
}
57+
58+
public ButtonImageEnum CancelCloseButtonImage
59+
{
60+
get { return _cancelCloseButtonImage; }
61+
set
62+
{
63+
_cancelCloseButtonImage = value;
64+
OnPropertyChanged();
65+
}
66+
}
67+
68+
public ICommand EditSaveCommand => new DelegateCommand(EditOrSave);
69+
70+
public ICommand CancelCloseCommand => new DelegateCommand(CancelOrClose);
71+
72+
public abstract void OnNavigatedTo(NavigationContext navigationContext);
73+
74+
public virtual bool IsNavigationTarget(NavigationContext navigationContext)
75+
{
76+
return true;
77+
}
78+
79+
public virtual void OnNavigatedFrom(NavigationContext navigationContext)
80+
{
81+
}
82+
83+
protected void SetEditMode(bool mode)
84+
{
85+
EditMode = mode;
86+
if (mode)
87+
{
88+
EditSaveMessage = Translate("Save");
89+
CancelCloseMessage = Translate("Cancel");
90+
EditSaveButtonImage = ButtonImageEnum.Check;
91+
CancelCloseButtonImage = ButtonImageEnum.WindowClose;
92+
}
93+
else
94+
{
95+
EditSaveMessage = Translate("Edit");
96+
CancelCloseMessage = Translate("Close");
97+
EditSaveButtonImage = ButtonImageEnum.Edit;
98+
CancelCloseButtonImage = ButtonImageEnum.Clear;
99+
}
100+
}
101+
102+
protected abstract void Cancel();
103+
104+
protected abstract void Close();
105+
106+
protected abstract void Edit();
107+
108+
protected abstract void Save();
109+
110+
private void CancelOrClose()
111+
{
112+
if (EditMode)
113+
{
114+
Cancel();
115+
}
116+
else
117+
{
118+
Close();
119+
}
120+
}
121+
122+
private void EditOrSave()
123+
{
124+
if (EditMode)
125+
{
126+
Save();
127+
}
128+
else
129+
{
130+
Edit();
131+
}
132+
}
133+
134+
public virtual bool HasUnsavedChanges()
135+
{
136+
return false;
137+
}
138+
139+
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Matisco.Domain;
2+
using Microsoft.Practices.ServiceLocation;
3+
using Prism.Mvvm;
4+
5+
namespace Example.BusinessApp.Infrastructure.Screens
6+
{
7+
public class ScreenBase : BindableBase
8+
{
9+
private ITranslationService _translationService;
10+
11+
protected ITranslationService TranslationService
12+
{
13+
get
14+
{
15+
if (_translationService == null)
16+
{
17+
_translationService = ServiceLocator.Current.GetInstance<ITranslationService>();
18+
}
19+
return _translationService;
20+
}
21+
}
22+
23+
protected string Translate(string code)
24+
{
25+
return TranslationService.GetTranslation(GetType().FullName + "." + code);
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using Example.BusinessApp.Infrastructure.Models;
3+
4+
namespace Example.BusinessApp.Infrastructure.Services
5+
{
6+
public interface IRoleService
7+
{
8+
IEnumerable<Role> Get();
9+
10+
Role GetById(int id);
11+
12+
SaveResult Update(Role role);
13+
14+
SaveResult Delete(int roleId);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Example.BusinessApp.Infrastructure.Models;
4+
5+
namespace Example.BusinessApp.Infrastructure.Services
6+
{
7+
public class RoleService : IRoleService
8+
{
9+
private readonly List<Role> _roles = new List<Role>
10+
{
11+
new Role
12+
{
13+
Id = 1,
14+
Description = "Salesmen"
15+
},
16+
new Role
17+
{
18+
Id = 2,
19+
Description = "Management"
20+
}
21+
};
22+
23+
public IEnumerable<Role> Get()
24+
{
25+
return _roles;
26+
}
27+
28+
public Role GetById(int id)
29+
{
30+
return _roles.Single(role => role.Id == id);
31+
}
32+
33+
public SaveResult Update(Role role)
34+
{
35+
var result = new SaveResult();
36+
37+
try
38+
{
39+
40+
var existingRole = GetById(role.Id);
41+
42+
existingRole.Description = role.Description;
43+
result.Succes = true;
44+
}
45+
catch
46+
{
47+
result.ValidationErrors.Add("Role not found.");
48+
}
49+
50+
return result;
51+
}
52+
53+
public SaveResult Delete(int roleId)
54+
{
55+
var result = new SaveResult();
56+
57+
try
58+
{
59+
60+
var existingRole = GetById(roleId);
61+
62+
_roles.Remove(existingRole);
63+
64+
result.Succes = true;
65+
}
66+
catch
67+
{
68+
result.ValidationErrors.Add("Role not found.");
69+
}
70+
71+
return result;
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace Example.BusinessApp.Infrastructure.Services
4+
{
5+
public class SaveResult
6+
{
7+
public bool Succes { get; set; }
8+
9+
public List<string> ValidationErrors { get; set; }
10+
11+
public SaveResult()
12+
{
13+
ValidationErrors = new List<string>();
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)