AccountManagerViewModel.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using AIPractice.LabellerServer.Managers;
  2. using System;
  3. using System.Collections.ObjectModel;
  4. namespace AIPractice.LabellerServer.ViewModels
  5. {
  6. public class AccountManagerViewModel:ViewModel
  7. {
  8. public ObservableCollection<AccountViewModel> Accounts { get; }
  9. public AccountManagerViewModel()
  10. {
  11. Accounts = new ObservableCollection<AccountViewModel>();
  12. var dataManager = ManagerContainer.GetManager<IDataManager>();
  13. var accounts = dataManager.GetAccounts();
  14. foreach(var account in accounts)
  15. {
  16. var accountViewModel = new AccountViewModel
  17. {
  18. Id = account.Id,
  19. Name = account.Name,
  20. Description = account.Description,
  21. Password = account.Password,
  22. CreatedTime = account.CreatedTime,
  23. Labels = account.Labels,
  24. IsReviewer = account.IsReviewer,
  25. Email = account.Email,
  26. };
  27. Accounts.Add(accountViewModel);
  28. }
  29. }
  30. public void AddAccount(AccountViewModel accountViewModel)
  31. {
  32. accountViewModel.CreatedTime = DateTime.Now;
  33. var dataManager = ManagerContainer.GetManager<IDataManager>();
  34. dataManager.AddAccount(accountViewModel.Account);
  35. Accounts.Add(accountViewModel);
  36. }
  37. public void DeleteAccount(AccountViewModel accountViewModel)
  38. {
  39. var dataManager = ManagerContainer.GetManager<IDataManager>();
  40. dataManager.DeleteAccount(accountViewModel.Account);
  41. Accounts.Remove(accountViewModel);
  42. }
  43. public void UpdateAccount(AccountViewModel accountViewModel)
  44. {
  45. var dataManager = ManagerContainer.GetManager<IDataManager>();
  46. dataManager.UpdateAccount(accountViewModel.Account);
  47. }
  48. }
  49. }