RecipeStepDeleteDialogViewModel.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using FurnaceUI.Models;
  6. namespace FurnaceUI.Views.Recipes
  7. {
  8. public class RecipeStepDeleteDialogViewModel:FurnaceUIViewModelBase
  9. {
  10. public RecipeDataBase Recipe { get; set; }
  11. private ObservableCollection<Step> _newSteps = new ObservableCollection<Step>();
  12. public ObservableCollection<Step> NewSteps
  13. {
  14. get
  15. {
  16. if (Recipe != null && Recipe.Steps != null)
  17. {
  18. _newSteps.Clear();
  19. Recipe.Steps.Where(x => !x.Name.ToLower().Contains("standby") && !x.Name.ToLower().Contains("end")).ToList().ForEach(s => _newSteps.Add(s));
  20. return _newSteps;
  21. }
  22. else
  23. {
  24. return null;
  25. }
  26. }
  27. }
  28. public RecipeStepDeleteDialogViewModel(RecipeDataBase CurrentRecipe)
  29. {
  30. Recipe = CurrentRecipe;
  31. }
  32. public void DeleteSteps()
  33. {
  34. List<Step> test = new List<Step>();
  35. ObservableCollection<Step> TempSteps = Recipe.Steps;
  36. test = TempSteps.Where(x => x.IsChecked == true).ToList();
  37. foreach (var item in test)
  38. {
  39. Recipe.Steps.Remove(item);
  40. }
  41. Step step = Recipe.Steps.FirstOrDefault(x => x.Name == "Standby");
  42. for (int i = 0; i < Recipe.Steps.Count; i++)
  43. {
  44. if (step == null)
  45. {
  46. Recipe.Steps[i].StepNo = i + 1;
  47. }
  48. else
  49. {
  50. Recipe.Steps[i].StepNo = i;
  51. }
  52. }
  53. }
  54. }
  55. }