Blogs

Gary's Blog

XAF - Domain Components How-to: Implement Notes Functionality in a Business Entity

     

This post may be outdated. For the latest Domain Components concepts and examples refer to the current online documentation.

Notes, every business needs them. Every person in the company who has contact with a customer has to be able to record that fact in a CRM system. The last thing you want to do is to be a salesmen phoning a customer, in the hope of getting a large order, only to discover that the last contact the customer had with your company was to complain bitterly about the shoddy service he just received. If there was a note in the system to that fact, then you could either phone once it’s been resolved, or you could change your sales tactic.

Of course, saying you need notes is one thing, actually implementing it is quite another, especially if your class hierarchy already exists. You have to introduce the Note type, you have to create a member on the business objects to hold that new type, and most painful of all, you have to make room on the UI for the new note type. All and all you are in a world of pain. Now XAF can help you with the UI stuff, it will scaffold an appropriate UI for your types, but that still doesn’t save you from the pain of all the changes you have to make to your types.

Well enter Domain Components to save the day! The Domain Component technology will do all that hard work for you. First, let’s declare an INote interface:

[DomainComponent]
[XafDefaultProperty("Title")]
public interface INote {
    [RuleRequiredField(NoteValidationRules.NoteTitleIsRequired, DefaultContexts.Save)]
    [FieldSize(255)]
    string Title { get; set; }

    [FieldSize(4000)]
    string Description { get; set; }
    
    IPersistentFileData Attachment { get; set; }
}

As you can see it has a mandatory title property, so that you can name your note something meaningful, a description field, big enough to hold a reasonable sized note, and a field to hold an attachment, in case you wish to append a file to the note. Oh, and here’s the NoteValidationRules class that we’ve used in the RuleRequiredField:

public class NoteValidationRules {
    public const string NoteTitleIsRequired = "NoteTitleIsRequired";
}

This pattern let’s us extend this behaviour, if we need to, at a later date.

So far so good, but it’s not really useful to have one note attached to a business class, what we really need is a notes collection, so let’s go ahead and define something to hold a collection of notes:

[DomainComponent]
public interface INotes {
    [DevExpress.ExpressApp.DC.Aggregated]
    IList<INote> Notes { get; }
}

This notes interface that we’ve just created is a pluggable part of the notes extension and now we can use it wherever we wish:

public interface ICRMActivity : IActivity, INotes ...
public interface ICRMContact : IContact, INotes, ...
public interface ICRMInvoice : IInvoice, INotes, ...

And so on and so forth.

So, as you can see, Domain Components, have saved us an awful lot of work when it comes to adding this notes functionality. After it has been added to the Contact, the UI looks like this:

Notes on the Contact UI

And it looks like this, when added to the Invoice:

Notes on the Invoice UI

As you can see, in this post, I have not covered testing, neither unit testing, with something like NUnit, nor functional testing with EasyTest. I didn’t add the testing stuff in as I thought it might complicate matters, but if you feel that it wouldn’t and you’d like to see testing covered in this series, then let me know in the comments and I’ll add it to the next one.

Well, that’s all for this post, until next time, happy XAF’ing! Smile

Published Mar 25 2011, 06:27 PM by Gary Short (DevExpress)
Filed under: , ,
Technorati tags: XAF, DC, Domain Components
Bookmark and Share

Comments

 

Julien Ferraro said:

Hi Gary,

The thing I would like to hear about is EasyTest. I still don't really see the point of using it. Unit tests, in XAF, can do most of the testing work.

Julien

March 27, 2011 11:08 PM
 

Alberto Cortes said:

I would like o see some examples using Unit Test and Easy Test. Thanks.

March 28, 2011 11:45 AM
 

Dennis (DevExpress Support) said:

@All: Thank you for the feedback, guys! We see your points.

@Alberto: Meantime, you can find the tests within XCRM demo very helpful. See also my comments to the community.devexpress.com/.../xaf-mastering-domain-components-a-how-to-series.aspx blog post.

March 28, 2011 11:28 PM
 

CARLOS MELGAR said:

Hi Gary,

Would love to see Unit Tests and Easy Tests in your posts.

Carlos

April 2, 2011 10:25 AM
 

Randy Trexler said:

where does IPersistentFileData live in the INote.Attachment example?

April 7, 2011 12:25 AM
 

Randy Trexler said:

...meaning which namespace/assembly can I find that?

April 7, 2011 7:58 AM
 

Dennis (DevExpress Support) said:

@Carlos: Thank you for the feedback. As I already mentioned in my reply to Alberto, we will cover these areas.

@Randy: Please check out the DomainComponents.Common project in the XCRM demo, distributed with XAF.

April 7, 2011 2:11 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.