I am stuck in a design issue. My problem is that my solution to the problem is not clean. And code looks not nice.
This is what I want to do:
I have an plain class with properies storing values. The class values must validate to certain rules.
This is a simplified example: A value class:
class RecivedOrder
{
public AgreementId { get; set; }
public OrderNr { get; set; }
public Items { get; set; }
public ProductId { get; set; }
public ValidProductId { get; set; }
public InStock { get; set; }
public CustomerId { get; set; }
public NameOfCustomer { get; set; }
//..and many more properties..
}
Validations/Update is done one the class like this:
foreach (RecivedOrder o in RecivedDocument.Orders)
{
RecivedOrder.AgreementId = CheckIfValidAgreementId(o.AgreementId );
RecivedOrder.ValidProductId = (bool)CheckIfValidProductId(o.ProductId);
RecivedOrder.InStock = (bool)CheckProductIsInStock(o.ProductId);
RecivedOrder.NameOfCustomer = GetNameOfCustomer(o.CustomerId);
// ...and many more checks/validations....
// The check methodes can do call to database..
}
What I am looking for is a good design pattern for this. Or a cleaner way to do this?
Best Regards Fredrik
Aucun commentaire:
Enregistrer un commentaire