public MvcViewScaffolderViewModel(MvcViewScaffolderModel model) : base(model) { if (model == null) { throw new ArgumentNullException("model"); } this.Model = model; this.ViewTemplatesInternal = model.ViewTemplates; ViewTemplate viewTemplate = new ViewTemplate(MvcViewTemplates.Empty, false); if (this.ViewTemplatesInternal.Any <ViewTemplate>()) { this.ViewTemplate = this.ViewTemplatesInternal.FirstOrDefault <ViewTemplate>((ViewTemplate view) => view.Equals(viewTemplate)) ?? this.ViewTemplatesInternal.First <ViewTemplate>(); this.ViewTemplateSearchText = this.ViewTemplate.DisplayName; this.IsViewTemplateSelectorVisible = this.ViewTemplatesInternal.Count <ViewTemplate>() > 1; } this.ViewTemplates = CollectionViewSource.GetDefaultView(this.ViewTemplatesInternal); this.ViewTemplates.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending)); this.IsPartialViewSelected = model.IsPartialViewSelected; this.IsReferenceScriptLibrariesSelected = model.IsReferenceScriptLibrariesSelected; this.IsLayoutPageSelected = model.IsLayoutPageSelected; this.LayoutPageFile = model.LayoutPageFile; this.ViewName = model.ViewName; base.SetValidationMessage(model.ValidateViewName(this.ViewName), "ViewName"); this.DataContextTypesInternal = new ObservableCollection <ModelType>(); this.ModelTypesInternal = new ObservableCollection <ModelType>(); foreach (ModelType modelType in this.Model.ModelTypes) { this.ModelTypesInternal.Add(modelType); } foreach (ModelType dataContextType in this.Model.DataContextTypes) { this.DataContextTypesInternal.Add(dataContextType); } this.DataContextTypes = new ListCollectionView(this.DataContextTypesInternal) { CustomSort = new DataContextModelTypeComparer() }; this.ModelTypes = CollectionViewSource.GetDefaultView(this.ModelTypesInternal); this.ModelTypes.SortDescriptions.Add(new SortDescription("ShortTypeName", ListSortDirection.Ascending)); this.IsDataContextSelectorVisible = this.DataContextTypesInternal.Any <ModelType>(); if (this.IsDataContextSelectorVisible && model.DataContextType != null) { this.DataContextType = this.Model.DataContextType; this.DataContextTypeName = this.DataContextType.DisplayName; } if (this.ViewTemplate == null) { base.SetValidationMessage(this.Model.ValidateViewTemplate(null), "ViewTemplate"); } else if (!this.ViewTemplate.IsModelRequired) { base.SetValidationMessage(null, "ModelType"); } else { base.SetValidationMessage(this.Model.ValidateModelType(null), "ModelType"); } this.SelectLayoutCommand = new RelayCommand(new Action <object>(this.SelectLayout)); }
public MvcViewScaffolderModel(CodeGenerationContext context) : base(context) { string str = null; this.IsLayoutPageSelected = true; this.IsPartialViewSelected = false; this.IsReferenceScriptLibrariesSelected = true; base.AreaName = MvcViewScaffolderModel.GetAreaNameFromSelection(context.ActiveProjectItem); this.ViewTemplates = Enumerable.Empty <ViewTemplate>(); IEnumerable <CodeType> allCodeTypes = base.ServiceProvider.GetService <ICodeTypeService>().GetAllCodeTypes(base.ActiveProject); List <ModelType> modelTypes = new List <ModelType>(); List <ModelType> modelTypes1 = new List <ModelType>(); foreach (CodeType allCodeType in allCodeTypes) { if (!Microsoft.AspNet.Scaffolding.EntityFramework.CodeTypeExtensions.IsValidDbContextType(allCodeType)) { if (!Microsoft.AspNet.Scaffolding.EntityFramework.CodeTypeExtensions.IsValidWebProjectEntityType(allCodeType)) { continue; } modelTypes.Add(new ModelType(allCodeType)); } else { modelTypes1.Add(new ModelType(allCodeType)); } } this.ModelTypes = modelTypes; this.DataContextTypes = modelTypes1; this.IsModelClassSupported = true; if (!context.Items.TryGetProperty <string>("DefaultViewName", out str)) { this.ViewName = this.GetGeneratedName(MvcProjectUtil.ViewName, this.ViewFileExtension); } else { this.ViewName = str; } if (context.Items.TryGetProperty <string>("ControllerFolderName", out str) && str != null) { base.SelectionRelativePath = Path.Combine(base.AreaRelativePath, "Views", str); } }
public SelectModelWindow(MvcViewScaffolderModel viewModel) { InitializeComponent(); DataContext = viewModel; }