- MigrateToMvvmMef-Part3_Src.zip
- MigrateToMvvmMef-Part3_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- AnotherXap.Models
- AnotherXap.ViewModels
- AnotherXap.Views
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- SaveState
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part1_Src.zip
- MigrateToMvvmMef-Part1_Src
- ProductApp.Common
- ProductApp.Main
- ProductApp.sln
- ProductApp.suo
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part2_Src.zip
- MigrateToMvvmMef-Part2_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
|
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using ProductApp.Common;
using ProductRiaLib.Web.Models;
using ProductRiaLib.Web.Services;
namespace ProductApp.Models
{
[Export(ModuleID.ProductListModel, typeof(IProductListModel))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class ProductListModel : IProductListModel
{
private ProductDomainContext _ctx;
// Define event handlers for data operations
public event EventHandler<QueryResultsArgs<Category>> GetCategoryLookupComplete;
public event EventHandler<QueryResultsArgs<Product>> GetCategorizedProductsComplete;
public event EventHandler<SubmitOperationArgs> SaveChangesComplete;
public ProductListModel()
{
if (_ctx == null)
{
_ctx = new ProductDomainContext();
_ctx.PropertyChanged += _ctx_PropertyChanged;
}
}
private void _ctx_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "HasChanges":
HasChanges = _ctx.HasChanges;
break;
case "IsLoading":
IsBusy = _ctx.IsLoading;
break;
case "IsSubmitting":
IsBusy = _ctx.IsSubmitting;
break;
}
}
public void GetCategoryLookup()
{
DataAsyncHandlers.LoadQueryAsync(_ctx, _ctx.GetCategoriesQuery(), this, GetCategoryLookupComplete);
}
public void GetCategorizedProducts(int categoryId)
{
DataAsyncHandlers.LoadQueryAsync(_ctx, _ctx.GetCategorizedProductQuery(categoryId), this, GetCategorizedProductsComplete);
}
public void SaveChanges(string operationType)
{
CurrentOperation = operationType;
DataAsyncHandlers.SaveChangesAsync(_ctx, this, SaveChangesComplete);
}
public void AddNewProduct(Product addedProduct)
{
_ctx.Products.Add(addedProduct);
SaveChanges(OperationTypes.AddNew);
}
public void DeleteProduct(Product deletingProduct)
{
_ctx.Products.Remove(deletingProduct);
SaveChanges(OperationTypes.Delete);
}
public string CurrentOperation { get; set; }
private Boolean _hasChanges;
//
public Boolean HasChanges
{
get
{
return _hasChanges;
}
private set
{
if (_hasChanges != value)
{
_hasChanges = value;
OnPropertyChanged("HasChanges");
}
}
}
private Boolean _isBusy;
//
public Boolean IsBusy
{
get
{
return _isBusy;
}
private set
{
if (_isBusy != value)
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
}
// Implement INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
|
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.
Shenwei is a software developer and architect, and has been working on business applications using Microsoft and Oracle technologies since 1996. He obtained Microsoft Certified Systems Engineer (MCSE) in 1998 and Microsoft Certified Solution Developer (MCSD) in 1999. He has experience in ASP.NET, C#, Visual Basic, Windows and Web Services, Silverlight, WPF, JavaScript/AJAX, HTML, SQL Server, and Oracle.