forked from emreeren/SambaPOS-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserViewModel.cs
73 lines (63 loc) · 2.02 KB
/
UserViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using FluentValidation;
using SamplePrism.Domain.Models.Users;
using SamplePrism.Localization.Properties;
using SamplePrism.Presentation.Common.ModelBase;
using SamplePrism.Presentation.Services.Common;
namespace SamplePrism.Modules.UserModule
{
[Export, PartCreationPolicy(CreationPolicy.NonShared)]
public class UserViewModel : EntityViewModelBase<User>
{
private bool _edited;
public UserViewModel()
{
EventServiceFactory.EventService.GetEvent<GenericEvent<UserRole>>().Subscribe(x => RaisePropertyChanged(() => Roles));
}
public string PinCode
{
get
{
if (_edited) return Model.PinCode;
return !string.IsNullOrEmpty(Model.PinCode) ? "********" : "";
}
set
{
if (Model.PinCode == null || !Model.PinCode.Contains("*") && !string.IsNullOrEmpty(value))
{
_edited = true;
Model.PinCode = value;
RaisePropertyChanged(() => PinCode);
}
}
}
public UserRole Role { get { return Model.UserRole; } set { Model.UserRole = value; } }
public IEnumerable<UserRole> Roles { get; private set; }
public override Type GetViewType()
{
return typeof(UserView);
}
public override string GetModelTypeString()
{
return Resources.User;
}
protected override void Initialize()
{
Roles = Workspace.All<UserRole>();
}
protected override AbstractValidator<User> GetValidator()
{
return new UserValidator();
}
}
internal class UserValidator : EntityValidator<User>
{
public UserValidator()
{
RuleFor(x => x.PinCode).Length(4, 20);
RuleFor(x => x.UserRole).NotNull();
}
}
}