|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technewlogic.ObjectLounge;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using Technewlogic.ObjectLounge.Framework.Proxy;
using Technewlogic.ObjectLounge.Framework.Validation;
namespace Technewlogic.ObjectLounge.Test.Model
{
[Identity("_key")]
public class Customer : BOBase
{
#region Constants
public const string NewName = "New Customer";
public const string SKName = "S&K Anlagentechnik";
public const string PizzaInderName = "Pizza Express";
#endregion
public Customer()
{
}
public Guid _key = Guid.NewGuid();
public int _accountNumber;
public virtual int AccountNumber
{
get
{
return _accountNumber;
}
set
{
_accountNumber = value;
SendPropertyChanged("AccountNumber");
}
}
public string _name;
public virtual string Name
{
get
{
return _name;
}
set
{
_name = value;
SendPropertyChanged("Name");
}
}
[ValidationRule]
protected ValidationResult ValidateAccountNumber()
{
if (Context.EnableValidation)
{
if (_accountNumber > 0 && _accountNumber < 1000)
return ValidationResult.Success();
else
return ValidationResult.Failure("Invalid account number.");
}
return ValidationResult.Success();
}
public bool ContextAccessRuleTriggered;
[ValidationRule]
protected ValidationResult ValidateContextAccess()
{
ContextAccessRuleTriggered = true;
if (Context.EnableValidation)
{
var unique = !Context.Customers
.Where(it => it != this)
.Any(it => it.AccountNumber == this.AccountNumber);
if (unique)
return ValidationResult.Success();
else
return ValidationResult.Failure("Account number is not unique.");
}
return ValidationResult.Success();
}
[ValidationRule]
protected ValidationResult ValidateName()
{
if (Context.EnableValidation)
{
// Macht Probleme bei alles Tests, da das Framework nun automatisch validiert
if (string.IsNullOrEmpty(_name))
return ValidationResult.Failure("Customer has no name.");
else
return ValidationResult.Success();
}
return ValidationResult.Success();
}
[Composition]
public virtual IList<Order> Orders { get; protected set; }
public override string ToString()
{
return this.GetType().Name + ": " + Name;
}
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.