This project is read-only.

A simple example

Topics: User Forum
Dec 10, 2006 at 3:28 PM
Could someone post a simple example of how you envision this to work? I've read through the documents but there's not much there. I'm trying to understand why I would use this, as opposed to doing it myself which I already do.

Thanks.
Dec 11, 2006 at 11:04 PM
We´ll use a login form as sample ok?

Let´s say for example that you have this model:

public interface ILoginForm : IModel {
string Username { get;set;}
string Password { get;set;}
event EventHandler Authenticate;
bool IsAuthenticated { get;set;}
}

where the Authenticate event is raised when the user clicks the login button (the user control where the login button stands implement ILoginForm).

Then you´d implement the LoginFormPresenter as shown below:
public class LoginFormPresenter : Presenter<ILoginForm> {
public LoginFormPresenter(ILoginForm view) : base(view) { }

protected override void InitCore(bool isFirstCall) {
this.Model.Authenticate += delegate(object sender, EventArgs e) {
this.Model.IsAuthenticated = (this.Model.Username == "correct" &&
this.Model.Password == "correct");
};
}

protected override void LoadCore(bool isFirstCall) {
if (isFirstCall) {
this.Model.IsAuthenticated = false;
}
}
}

This presenter shows that when the view is first loaded the IsAuthenticated property is set to false, and once the Authenticate evente is raised the presenter sets IsAuthenticated to the value of an authentication (very silly in this sample).

Basically this is all you have to implement (there are a few more details, but they´ll all be in the final version of the framework´s documentation).

Of course you still have to implement the Views (Unit Test and ASP.Net) in my case, but only the layout part.

If you have any more doubts, please feel free to ask and someone in the team will answer.

Bernardo Heynemann