/// <summary> /// Creates a mapping from a collection of view models to a collection of entity stubs; /// </summary> /// <remarks> /// An entity stub is an instance of an entity with only its <see cref="IEntity.Id"/> set. It is useful for manipulating relationships /// without retrieving entire entities from the database, because you can set it to a navigation property or add it to a navigation /// collection and the database will create the relation based upon the Id. Note that in order to modify the other properties of /// the stub entity, it must be attached to the context in the unchanged state (the default of <see cref="DbSet{TEntity}.Attach"/>. /// </remarks> /// <typeparam name="TRelatedViewModel">The type of the related entity's view model</typeparam> /// <typeparam name="TRelatedEntity">The type of the related entity</typeparam> /// <returns> /// A mapping configuration /// </returns> public IMappingExpression <Choices <TRelatedViewModel>, ICollection <TRelatedEntity> > CreateChoicesToEntitiesMap <TRelatedViewModel, TRelatedEntity>(IBootstrapRepository <TRelatedEntity> repository) where TRelatedViewModel : IEntityViewModel where TRelatedEntity : class, IEntity, new() { var mappingExpression = Mapper.CreateMap <Choices <TRelatedViewModel>, ICollection <TRelatedEntity> >(); var converter = new ChoicesToEntitiesConverter <TRelatedViewModel, TRelatedEntity>(repository); mappingExpression.ConvertUsing(converter); return(mappingExpression); }
CreateChoiceToEntityMap <TRelatedViewModel, TRelatedEntity>(IBootstrapRepository <TRelatedEntity> repository) where TRelatedViewModel : class, IEntityViewModel where TRelatedEntity : class, IEntity, new() { var mappingExpression = Mapper.CreateMap <Choice <TRelatedViewModel>, TRelatedEntity>(); var converter = new ChoiceToEntityConverter <TRelatedViewModel, TRelatedEntity>(repository); mappingExpression.ConvertUsing(converter); return(mappingExpression); }
public RolesController(IRolesRepository repository, IBootstrapRepository <Employee> employeesRepository) : base(repository) { this.Config.Sort = Sort.By(e => e.Title).ThenBy(e => e.Created); this.Config.EntityLabelSelector = e => e.Title; this.Config.ViewModelLabelSelector = vm => vm.Title; this.Config.Relation(e => e.Employees) .HasOptions(e => employeesRepository.GetAll()) .UsesLabel <EmployeeOption>(vm => vm.Name); //this.Config.Relation(e => e.ParentRole) // .HasOptions(e => repository.Items) // .UsesLabel<RoleOption>(vm => vm.Title) // .CanChooseSelf(false); }
public BootstrapControllerBase(IBootstrapRepository <TEntity> repository) { this.Repository = repository; this.Config = new BootstrapControllerConfig <TEntity, TViewModel> { CreateViewName = "Create", ReadViewName = "Read", UpdateViewName = "Update", ListViewName = "List", EntityLabelSelector = e => e.Id.ToString(), ViewModelLabelSelector = vm => vm.Id.ToString(), Sort = Sort.ByDescending(e => e.Created) }; this.MappingCreator = new MappingCreator <TEntity>(this.Config.RelationsConfig); this.MappingCreator.InitializeMapping <TViewModel>(DependencyResolver.Current); }
public UserProfilesController(IBootstrapRepository <ExampleUserProfile> repository) : base(repository) { }
public ChoicesToEntitiesConverter(IBootstrapRepository <TRelatedEntity> repository) { this.repository = repository; }