private void SaveAs() { RecipeTemplate model = new RecipeTemplate(); //实例化一个新的model model.Name = _selectedItem._recipeTemplate.Name; //model.Current = _selectedItem._recipeTemplate.Current; //model.Temperature = _selectedItem._recipeTemplate.Temperature; foreach (var step in _selectedItem._recipeTemplate.StepV2s) { //var m = new StepV2(step.StepTemplate); var newstep = step.Clone(); model.StepV2s.Add(newstep); } RecipeTemplateEditViewModel viewmodel = new RecipeTemplateEditViewModel( model ); //实例化一个新的view model //viewmodel.Id = _selectedItem.Id; viewmodel.DisplayName = "Recipe Template-Save As"; viewmodel.commandType = CommandType.SaveAs; var RecipeViewInstance = new RecipeTemplateView(); //实例化一个新的view RecipeViewInstance.DataContext = viewmodel; RecipeViewInstance.ShowDialog(); if (viewmodel.IsOK == true) { _recipeTemplateServcie.SuperAdd(model); } }
private void Create() { RecipeTemplate model = new RecipeTemplate(); //实例化一个新的model RecipeTemplateEditViewModel viewmodel = new RecipeTemplateEditViewModel( model ); //实例化一个新的view model viewmodel.DisplayName = "Recipe Template-Create"; viewmodel.commandType = CommandType.Create; var RecipeViewInstance = new RecipeTemplateView(); //实例化一个新的view RecipeViewInstance.DataContext = viewmodel; RecipeViewInstance.ShowDialog(); //设置viewmodel属性 if (viewmodel.IsOK == true) { //foreach (var step in model.Steps) //{ // int order = 1; // step.Order = order++; //} _recipeTemplateServcie.SuperAdd(model); } }