Created
March 23, 2010 23:00
-
-
Save jfromaniello/341790 to your computer and use it in GitHub Desktop.
cpbt-postsharp-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PersistenceConversational(MethodsIncludeMode = MethodsIncludeMode.Explicit)] | |
public class ProductEditPresenter | |
: IInitializablePresenter | |
{ | |
private readonly IDao<Product> daoProduct; | |
private readonly IDao<Category> daoCategory; | |
private readonly IProductEditView productEditView; | |
public ProductEditPresenter( | |
IDaoFactory daoFactory, | |
IProductEditView productEditView) | |
{ | |
daoProduct = daoFactory.GetDaoOf<Product>(); | |
daoCategory = daoFactory.GetDaoReadOnlyOf<Category>(); | |
this.productEditView = productEditView; | |
productEditView.SaveClicked += ViewSaveClicked; | |
productEditView.CancelClicked += ViewCancelClicked; | |
} | |
#region IInitializablePresenter Members | |
[PersistenceConversation(EndMode = EndMode.End)] | |
public void Initialize() | |
{ | |
View.Categories = daoCategory.GetAll().OrderBy(c => c.Name); | |
View.Product = new Product(); | |
} | |
#endregion | |
public override void Activate() | |
{ | |
ViewManager.ShowDialog(View); | |
} | |
[PersistenceConversation(EndMode = EndMode.Abort)] | |
private void ViewCancelClicked(object sender, EventArgs e) | |
{ | |
View.Close(); | |
} | |
[PersistenceConversation(EndMode = EndMode.End)] | |
private void ViewSaveClicked(object sender, EventArgs e) | |
{ | |
daoProduct.MakePersistent(View.Product); | |
View.Close(); | |
} | |
[PersistenceConversation(EndMode = EndMode.Continue)] | |
public void Initialize(int id) | |
{ | |
View.Product = daoProduct.Get(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment