generated from ricardo/MVCLogin
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using BaseDomain;
|
|
|
|
namespace SumaTube.Domain
|
|
{
|
|
public class Name : AValueObject
|
|
{
|
|
public Name(string fullName)
|
|
{
|
|
this.FullName = fullName;
|
|
var names = fullName.Split(' ');
|
|
if (names.Length >= 2)
|
|
{
|
|
this.FirstName = names[0];
|
|
this.LastName = names[names.Length - 1];
|
|
}
|
|
}
|
|
|
|
public Name(string firstName, string lastName)
|
|
{
|
|
this.FirstName = firstName;
|
|
this.LastName = lastName;
|
|
}
|
|
|
|
public string FullName { get; private set; }
|
|
public string FirstName { get; private set; }
|
|
public string LastName { get; private set; }
|
|
|
|
public override bool GetValidationExpression()
|
|
{
|
|
return this.IsValid = this.IsValidName(FullName);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.FullName;
|
|
}
|
|
|
|
protected override IEnumerable<object> GetEqualityComponents()
|
|
{
|
|
yield return this.FullName;
|
|
}
|
|
|
|
private bool IsValidName(string fullName)
|
|
{
|
|
return fullName.Contains(' ');
|
|
}
|
|
|
|
public static implicit operator string(Name name) => name.FullName;
|
|
public static explicit operator Name(string fullname) => new Name(fullname);
|
|
}
|
|
}
|