|
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using Codebasement.DomainDrivenDesign.Basement.Attributes;
using Codebasement.DomainDrivenDesign.Basement.Basement;
using Codebasement.DomainDrivenDesign.Basement.Enums;
using Codebasement.DomainDrivenDesign.Model.ModelClasses;
namespace Codebasement.DomainDrivenDesign.Model.ModelClasses
{
/// <summary>
/// Contains a collection of <see cref="User"/> objects.
/// </summary>
[Serializable]
[Description("Defines a collection of Users")]
[XmlInclude(typeof (User))]
[Relatable(typeof (User), 1, CardinalityType.ExactlyAsCardinality)]
public sealed class Users : BasementObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Users"/> class.
/// </summary>
public Users()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Users"/> class.
/// </summary>
/// <param name="info">The info.</param>
/// <param name="context">The context.</param>
private Users(SerializationInfo info, StreamingContext context) : this()
{
ConstructParameters(info);
}
/// <summary>
/// Overridable core validation of a <see cref="BasementObject"/>. Usage intended for specific business model validations.
/// </summary>
protected override void ValidateCore()
{
/* BUSINESS RULE : User names must be unique */
ArrayList listUsers = new ArrayList();
Collection<BasementObject> collection = GetSubItems(typeof (User), true);
if (collection.Count > 0)
{
foreach (User item in collection)
{
if (!listUsers.Contains(item.Name))
listUsers.Add(item.Name);
else
{
// already present
string message = string.Format("Non-unique User name {0} in Users group.",
item.Name);
string solution = string.Format("Change the Name property of the User item.");
ValidationResult result = new ValidationResult(this, ValidationResultType.Error, message,
solution);
AddValidationResult(result);
}
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.