code_junkie

What is the best way to reuse pages from one website in another?

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public class SomePresenter
  2. {
  3. public ISomeView View{get; set;}
  4.  
  5. public void InitializeView()
  6. {
  7. //Setup all the stuff on the view the first time
  8.  
  9. View.Name = //Load from database
  10. View.Orders = //Load from database
  11. }
  12.  
  13. public void LoadView()
  14. {
  15. //Handle all the stuff that happens each time the view loads
  16. }
  17.  
  18. public Int32 AddOrder(Order newOrder)
  19. {
  20. //Code to update orders and then update the view
  21. }
  22. }
  23.  
  24. public interface ISomeView
  25. {
  26. String Name {get; set;}
  27. IList<Order> Orders{get; set;}
  28. }
  29.  
  30. public partial class SomeConcreteView : System.Web.UI.Page, ISomeView
  31. {
  32. public SomePresenter Presenter{get; set;}
  33.  
  34. public SomeConcreteView()
  35. {
  36. Presenter = new SomePresenter();
  37.  
  38. //Use the current page as the view instance
  39. Presenter.View = this;
  40. }
  41.  
  42. protected void Page_Load(object sender, EventArgs e)
  43. {
  44. if(!IsPostBack)
  45. {
  46. Presenter.InitializeView();
  47. }
  48.  
  49. Presenter.LoadView();
  50. }
  51.  
  52. //Implement your members to bind to actual UI elements
  53. public String Name
  54. {
  55. get{ return lblName.Text; }
  56. set{ lblName.Text = value; }
  57. }
  58.  
  59. public IList<Order> Orders
  60. {
  61. get{ return (IList<Order>)ordersGrid.DataSource; }
  62. set
  63. {
  64. ordersGrid.DataSource = value;
  65. ordersGrid.DataBind();
  66. }
  67. }
  68.  
  69. //Respond to UI events and forward them to the presenter
  70. protected virtual void addOrderButton_OnClick(object sender, EventArgs e)
  71. {
  72. Order newOrder = //Get order from UI
  73. Presenter.AddOrder(newOrder);
  74. }
  75. }
Add Comment
Please, Sign In to add comment