blob: 86866d8bebd4aa712d050e0ed3615bc264b7b422 (
plain)
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
|
using System.ComponentModel.DataAnnotations;
using Timeline.Entities;
using Timeline.Models.Validation;
namespace Timeline.Models
{
public class UserDetail
{
[MaxLength(10)]
public string Nickname { get; set; }
[ValidateWith(typeof(UserDetailValidators.QQValidator))]
public string QQ { get; set; }
[ValidateWith(typeof(UserDetailValidators.EMailValidator))]
public string EMail { get; set; }
[ValidateWith(typeof(UserDetailValidators.PhoneNumberValidator))]
public string PhoneNumber { get; set; }
public string Description { get; set; }
private static string CoerceEmptyToNull(string value)
{
if (string.IsNullOrEmpty(value))
return null;
else
return value;
}
public static UserDetail From(UserDetailEntity entity)
{
return new UserDetail
{
Nickname = CoerceEmptyToNull(entity.Nickname),
QQ = CoerceEmptyToNull(entity.QQ),
EMail = CoerceEmptyToNull(entity.EMail),
PhoneNumber = CoerceEmptyToNull(entity.PhoneNumber),
Description = CoerceEmptyToNull(entity.Description)
};
}
}
}
|