Created
May 13, 2013 07:13
-
-
Save yagopv/5566634 to your computer and use it in GitHub Desktop.
Value Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Address | |
/// For this Domain-Model, the Address is a Value-Object | |
/// </summary> | |
public class Address | |
{ | |
/// For this Domain-Model, the Address is a Value-Object | |
/// 'sets' are private as Value-Objects must be immutable, | |
/// so the only way to set properties is using the constructor | |
/// <summary> | |
/// Get or set the city of this address | |
/// </summary> | |
[StringLength(50, ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "Error_BadLenght")] | |
public string City { get; private set; } | |
/// <summary> | |
/// Get or set the country of this address | |
/// </summary> | |
[StringLength(50, ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "Error_BadLenght")] | |
public string Country { get; private set; } | |
/// <summary> | |
/// Get or set the zip code | |
/// </summary> | |
[StringLength(20, ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "Error_BadLenght")] | |
[DataType(DataType.PostalCode)] | |
public string ZipCode { get; private set; } | |
/// <summary> | |
/// Get or set address line 1 | |
/// </summary> | |
[StringLength(100, ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "Error_BadLenght")] | |
public string AddressLine1 { get; private set; } | |
/// <summary> | |
/// Get or set address line 2 | |
/// </summary> | |
[StringLength(100, ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "Error_BadLenght")] | |
public string AddressLine2 { get; private set; } | |
/// <summary> | |
/// Create a new instance of address specifying its values | |
/// </summary> | |
public Address(string city, string country, string zipCode, string addressLine1, string addressLine2) | |
{ | |
this.City = city; | |
this.Country = country; | |
this.ZipCode = zipCode; | |
this.AddressLine1 = addressLine1; | |
this.AddressLine2 = addressLine2; | |
} | |
/// <summary> | |
/// Check if this object has any value | |
/// </summary> | |
public bool HasValue | |
{ | |
get | |
{ | |
return (City != null || Country != null || ZipCode != null || AddressLine1 != null || AddressLine2 != null); | |
} | |
} | |
public Address() { } //required for EF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment