static IDictionary <Type, Aspect <TContext> > BuildAspectInstances <TContext>( IEnumerable <Type> aspects, TContext context ) { var dictionary = new Dictionary <Type, Aspect <TContext> >(); foreach (var aspect in aspects) { dictionary.Add(aspect, Aspect <TContext> .Create(aspect, context)); } return(dictionary); }
public BatchCreationDialogViewModel(IDataService <LabDbEntities> labDbData) : base() { _labDbData = labDbData; ColourList = _labDbData.RunQuery(new ColorsQuery()).ToList(); ConstructionList = _labDbData.RunQuery(new ConstructionsQuery()).ToList(); DoNotTest = false; ProjectList = _labDbData.RunQuery(new ProjectsQuery()).ToList(); Notes = ""; CancelCommand = new DelegateCommand <Window>( parentDialog => { parentDialog.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parentDialog => { if (AspectInstance == null) { AspectInstance = new Aspect() { Code = _aspectCode }; AspectInstance.Create(); } ; if (LineInstance == null) { LineInstance = new MaterialLine() { Code = _lineCode }; LineInstance.Create(); } if (RecipeInstance == null) { RecipeInstance = new Recipe() { Code = _recipeCode }; if (_selectedColour != null) { RecipeInstance.ColourID = _selectedColour.ID; } RecipeInstance.Create(); } else if (_selectedColour != null && RecipeInstance.ColourID != _selectedColour.ID) { _recipeInstance.ColourID = _selectedColour.ID; _recipeInstance.Update(); } Material tempMaterial = _labDbData.RunQuery(new MaterialQuery() { AspectID = _aspectInstance.ID, MaterialLineID = _lineInstance.ID, MaterialTypeID = _typeInstance.ID, RecipeID = _recipeInstance.ID }); if (tempMaterial != null) { bool requiresUpdate = false; if (_selectedConstruction != null && tempMaterial.ExternalConstructionID != _selectedConstruction.ID) { tempMaterial.ExternalConstructionID = _selectedConstruction.ID; requiresUpdate = true; } if (_selectedProject != null && tempMaterial.ProjectID != _selectedProject.ID) { tempMaterial.ProjectID = _selectedProject.ID; requiresUpdate = true; } if (requiresUpdate) { tempMaterial.Update(); } } if (tempMaterial == null) { tempMaterial = new Material() { AspectID = AspectInstance.ID, LineID = LineInstance.ID, RecipeID = RecipeInstance.ID, TypeID = TypeInstance.ID }; if (_selectedConstruction != null) { tempMaterial.ExternalConstructionID = _selectedConstruction.ID; } if (_selectedProject != null) { tempMaterial.ProjectID = _selectedProject.ID; } tempMaterial.Create(); } BatchInstance = new Batch() { DoNotTest = DoNotTest, FirstSampleArrived = false, MaterialID = tempMaterial.ID, ArchiveStock = 0, LongTermStock = 0, Notes = Notes, Number = _batchNumber }; if (SelectedTrialArea != null) { BatchInstance.TrialAreaID = SelectedTrialArea.ID; } BatchInstance.Create(); parentDialog.DialogResult = true; }, parentDialog => !HasErrors); BatchNumber = ""; TypeCode = ""; LineCode = ""; AspectCode = ""; RecipeCode = ""; }