using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using DevExpress.Mvvm; using DevExpress.Mvvm.POCO; using DevExpress.Mvvm.DataAnnotations; using DevExpress.DevAV.Common.Utils; using DevExpress.Mvvm.ViewModel; using DevExpress.Mvvm.DataModel; namespace DevExpress.DevAV.Common.ViewModel { /// /// The base class for a POCO view models exposing a collection of entities of a given type and CRUD operations against these entities. /// This is a partial class that provides extension point to add custom properties, commands and override methods without modifying the auto-generated code. /// /// An entity type. /// A primary key value type. /// A unit of work type. public partial class CollectionViewModel : CollectionViewModel where TEntity : class where TUnitOfWork : IUnitOfWork { /// /// Creates a new instance of CollectionViewModel as a POCO view model. /// /// A factory used to create a unit of work instance. /// A function that returns a repository representing entities of the given type. /// An optional parameter that provides a LINQ function used to customize a query for entities. The parameter, for example, can be used for sorting data. /// An optional parameter that provides a function to initialize a new entity. This parameter is used in the detail collection view models when creating a single object view model for a new entity. /// A function that is called before an attempt to create a new entity is made. This parameter is used together with the newEntityInitializer parameter. /// An optional parameter that used to specify that the selected entity should not be managed by PeekCollectionViewModel. public static CollectionViewModel CreateCollectionViewModel( IUnitOfWorkFactory unitOfWorkFactory, Func> getRepositoryFunc, Func, IQueryable> projection = null, Action newEntityInitializer = null, Func canCreateNewEntity = null, bool ignoreSelectEntityMessage = false, UnitOfWorkPolicy unitOfWorkPolicy = UnitOfWorkPolicy.Individual) { return ViewModelSource.Create(() => new CollectionViewModel(unitOfWorkFactory, getRepositoryFunc, projection, newEntityInitializer, canCreateNewEntity, ignoreSelectEntityMessage, unitOfWorkPolicy)); } /// /// Initializes a new instance of the CollectionViewModel class. /// This constructor is declared protected to avoid an undesired instantiation of the CollectionViewModel type without the POCO proxy factory. /// /// A factory used to create a unit of work instance. /// A function that returns a repository representing entities of the given type. /// An optional parameter that provides a LINQ function used to customize a query for entities. The parameter, for example, can be used for sorting data. /// An optional parameter that provides a function to initialize a new entity. This parameter is used in the detail collection view models when creating a single object view model for a new entity. /// A function that is called before an attempt to create a new entity is made. This parameter is used together with the newEntityInitializer parameter. /// An optional parameter that used to specify that the selected entity should not be managed by PeekCollectionViewModel. protected CollectionViewModel( IUnitOfWorkFactory unitOfWorkFactory, Func> getRepositoryFunc, Func, IQueryable> projection = null, Action newEntityInitializer = null, Func canCreateNewEntity = null, bool ignoreSelectEntityMessage = false, UnitOfWorkPolicy unitOfWorkPolicy = UnitOfWorkPolicy.Individual ) : base(unitOfWorkFactory, getRepositoryFunc, projection, newEntityInitializer, canCreateNewEntity, ignoreSelectEntityMessage, unitOfWorkPolicy) { } } /// /// The base class for a POCO view models exposing a collection of entities of a given type and CRUD operations against these entities. /// This is a partial class that provides extension point to add custom properties, commands and override methods without modifying the auto-generated code. /// /// A repository entity type. /// A projection entity type. /// A primary key value type. /// A unit of work type. public partial class CollectionViewModel : CollectionViewModelBase where TEntity : class where TProjection : class where TUnitOfWork : IUnitOfWork { /// /// Creates a new instance of CollectionViewModel as a POCO view model. /// /// A factory used to create a unit of work instance. /// A function that returns a repository representing entities of the given type. /// A LINQ function used to customize a query for entities. The parameter, for example, can be used for sorting data and/or for projecting data to a custom type that does not match the repository entity type. /// An optional parameter that provides a function to initialize a new entity. This parameter is used in the detail collection view models when creating a single object view model for a new entity. /// A function that is called before an attempt to create a new entity is made. This parameter is used together with the newEntityInitializer parameter. /// An optional parameter that used to specify that the selected entity should not be managed by PeekCollectionViewModel. public static CollectionViewModel CreateProjectionCollectionViewModel( IUnitOfWorkFactory unitOfWorkFactory, Func> getRepositoryFunc, Func, IQueryable> projection, Action newEntityInitializer = null, Func canCreateNewEntity = null, bool ignoreSelectEntityMessage = false, UnitOfWorkPolicy unitOfWorkPolicy = UnitOfWorkPolicy.Individual) { return ViewModelSource.Create(() => new CollectionViewModel(unitOfWorkFactory, getRepositoryFunc, projection, newEntityInitializer, canCreateNewEntity, ignoreSelectEntityMessage, unitOfWorkPolicy)); } /// /// Initializes a new instance of the CollectionViewModel class. /// This constructor is declared protected to avoid an undesired instantiation of the CollectionViewModel type without the POCO proxy factory. /// /// A factory used to create a unit of work instance. /// A function that returns a repository representing entities of the given type. /// A LINQ function used to customize a query for entities. The parameter, for example, can be used for sorting data and/or for projecting data to a custom type that does not match the repository entity type. /// An optional parameter that provides a function to initialize a new entity. This parameter is used in the detail collection view models when creating a single object view model for a new entity. /// A function that is called before an attempt to create a new entity is made. This parameter is used together with the newEntityInitializer parameter. /// An optional parameter that used to specify that the selected entity should not be managed by PeekCollectionViewModel. protected CollectionViewModel( IUnitOfWorkFactory unitOfWorkFactory, Func> getRepositoryFunc, Func, IQueryable> projection, Action newEntityInitializer = null, Func canCreateNewEntity = null, bool ignoreSelectEntityMessage = false, UnitOfWorkPolicy unitOfWorkPolicy = UnitOfWorkPolicy.Individual ) : base(unitOfWorkFactory, getRepositoryFunc, projection, newEntityInitializer, canCreateNewEntity, ignoreSelectEntityMessage, unitOfWorkPolicy) { } } }