TaskCreatorUserControlViewModel.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using WpfApp29.Models;
  6. namespace WpfApp29.ViewModels
  7. {
  8. class TaskCreatorUserControlViewModel : BaseTaskUserControlViewModel
  9. {
  10. public TaskCreatorUserControlViewModel() { }
  11. public TaskCreatorUserControlViewModel(Task task) : base(task) { }
  12. public RelayCommand? _commandRemoveTask;
  13. public RelayCommand? CommandRemoveTask
  14. {
  15. get
  16. {
  17. return _commandRemoveTask ??= new RelayCommand(
  18. x =>
  19. {
  20. MainContext ctx = new MainContext();
  21. var task = ctx.Tasks.First(t => Task.Id == t.Id);
  22. task.StatusId = 4;
  23. ctx.SaveChanges();
  24. });
  25. }
  26. }
  27. public RelayCommand? _commandSetDoneTask;
  28. public RelayCommand? CommandSetDoneTask
  29. {
  30. get
  31. {
  32. return _commandSetDoneTask ??= new RelayCommand(
  33. x =>
  34. {
  35. MainContext ctx = new MainContext();
  36. ctx.Tasks.ToList().First(t => Task.Id == t.Id).StatusId = 3;
  37. ctx.SaveChanges();
  38. });
  39. }
  40. }
  41. }
  42. }