Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SomePresenter
- {
- public ISomeView View{get; set;}
- public void InitializeView()
- {
- //Setup all the stuff on the view the first time
- View.Name = //Load from database
- View.Orders = //Load from database
- }
- public void LoadView()
- {
- //Handle all the stuff that happens each time the view loads
- }
- public Int32 AddOrder(Order newOrder)
- {
- //Code to update orders and then update the view
- }
- }
- public interface ISomeView
- {
- String Name {get; set;}
- IList<Order> Orders{get; set;}
- }
- public partial class SomeConcreteView : System.Web.UI.Page, ISomeView
- {
- public SomePresenter Presenter{get; set;}
- public SomeConcreteView()
- {
- Presenter = new SomePresenter();
- //Use the current page as the view instance
- Presenter.View = this;
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if(!IsPostBack)
- {
- Presenter.InitializeView();
- }
- Presenter.LoadView();
- }
- //Implement your members to bind to actual UI elements
- public String Name
- {
- get{ return lblName.Text; }
- set{ lblName.Text = value; }
- }
- public IList<Order> Orders
- {
- get{ return (IList<Order>)ordersGrid.DataSource; }
- set
- {
- ordersGrid.DataSource = value;
- ordersGrid.DataBind();
- }
- }
- //Respond to UI events and forward them to the presenter
- protected virtual void addOrderButton_OnClick(object sender, EventArgs e)
- {
- Order newOrder = //Get order from UI
- Presenter.AddOrder(newOrder);
- }
- }
Add Comment
Please, Sign In to add comment