38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Assignment3.Models
|
|
{
|
|
public class Organization :IValidatableObject
|
|
{
|
|
[Key]
|
|
public Guid Id { get; private set; } = Guid.NewGuid();
|
|
|
|
[Required]
|
|
public DateTimeOffset CreationTime { get; private set; } = DateTimeOffset.UtcNow;
|
|
|
|
[Required]
|
|
[MaxLength(256)]
|
|
public string Name { get; set; }
|
|
|
|
[Required]
|
|
public String Type { get; set; }
|
|
|
|
[Required]
|
|
public string Address { get; set; }
|
|
|
|
// need to add error handling for Guid and possible Creation Time
|
|
// Can we have it so it just write over user input for creation time to current time?
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
// Custom Validation: Type must be one of the allowed values
|
|
string[] validTypes = { "Hospital", "Clinic", "Pharmacy" };
|
|
|
|
if (!Array.Exists(validTypes, t => t.Equals(Type, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
yield return new ValidationResult("The Organization Type must be one of the following values: Hospital, Clinic, Pharmacy.", new[] { "Type" });
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|