- castleextensionsdemo.zip
- App.Configuration
- App.Core
- App.Data
- Castle.ExtensibleDynamicProxy
- Castle.Facilities.PresentationModelIntegration
- CastleExtensionsDemo.sln
- libs
- AttachedCommandBehavior.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- Castle.MicroKernel.dll
- Castle.Windsor.dll
- PresentationModelBase
- WPFUI
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using PresentationModelBase;
namespace App.Core
{
[EncapsulatesProperty(typeof(Product), "Name")]
[EncapsulatesProperty(typeof(Product), "Price")]
[EncapsulatesProperty(typeof(Product), "Photography")]
public class ProductEditViewPresentationModel : SelectableViewPresentationModel, IEntityViewPresentationModel<Product>
{
public ProductEditViewPresentationModel(IMainViewPresentationModel mainView, IDao<Product> dao)
{
_mainView = mainView;
_dao = dao;
}
IMainViewPresentationModel _mainView;
IDao<Product> _dao;
public void OpenEditView()
{
_mainView.EditExisting<Product>(_entity);
}
public void SaveOrUpdate()
{
if (AskQuestion("Are you sure?") == QuestionResult.Yes)
{
_dao.SaveOrUpdate(_entity);
Close();
}
}
protected void ChoosePhoto()
{
FileInfo info = ChooseImage("Choose a photo for the product");
if (info != null)
{
byte[] data;
using (FileStream fs = info.OpenRead())
{
data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
}
SetPropertyValue("ProductPhotography", data);
}
}
public override string DisplayName
{
get
{
if (_entity == null)
return "Error - Invalid item";
if (_entity.Name == null ||
_entity.Name.Trim() == string.Empty)
return "New Product";
return string.Format("Editing product '{0}'", _entity.Name);
}
set
{
base.DisplayName = value;
}
}
private Product _entity;
public Product Entity
{
get
{
return _entity;
}
set
{
_entity = value;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.