Further AutoMapper changes

This commit is contained in:
Ben 2015-07-01 22:28:29 +01:00
parent 440254f3f8
commit c3d11da155
2 changed files with 7 additions and 9 deletions

View File

@ -28,8 +28,6 @@ namespace Filtration.ThemeEditor.Providers
public IThemeViewModel NewThemeForScript(ItemFilterScript script)
{
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
var themeComponentViewModels = Mapper.Map<ObservableCollection<ThemeComponentViewModel>>(script.ThemeComponents);
var themeViewModel = _themeViewModelFactory.Create();
themeViewModel.Initialise(themeComponentViewModels, true);
@ -40,9 +38,6 @@ namespace Filtration.ThemeEditor.Providers
public IThemeViewModel LoadThemeFromFile(string filePath)
{
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
var model = _themePersistenceService.LoadTheme(filePath);
var viewModel = Mapper.Map<IThemeViewModel>(model);
viewModel.FilePath = filePath;
@ -56,9 +51,6 @@ namespace Filtration.ThemeEditor.Providers
public void SaveTheme(IThemeViewModel themeViewModel, string filePath)
{
Mapper.CreateMap<IThemeViewModel, Theme>();
Mapper.CreateMap<ThemeComponentViewModel, ThemeComponent>();
var theme = Mapper.Map<Theme>(themeViewModel);
_themePersistenceService.SaveTheme(theme, filePath);
}

View File

@ -7,7 +7,9 @@ using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.Windsor;
using Castle.Windsor.Installer;
using Filtration.ObjectModel;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Properties;
using Filtration.ThemeEditor.ViewModels;
using Filtration.ViewModels;
using Filtration.Views;
@ -50,6 +52,10 @@ namespace Filtration
.ForMember(dest => dest.IsExpanded,
opts => opts.UseValue(false));
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>().ReverseMap();
Mapper.CreateMap<IThemeViewModel, Theme>();
Mapper.AssertConfigurationIsValid();
var mainWindow = _container.Resolve<IMainWindow>();