Advertisement
Guest User

Untitled

a guest
May 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. public class MariaDBDialogViewModel : ValidatableBindableBase, IRegionManagerAware
  2. {
  3. public MariaDBDialogViewModel()
  4. {
  5. SaveCommand = new DelegateCommand(OnSaveExecute, CanExecuteSave);
  6. }
  7.  
  8. #region Methods
  9.  
  10. //TODO:
  11. private bool CanExecuteSave()
  12. {
  13. return true;
  14. }
  15.  
  16. /// <summary>
  17. /// Save Data for Maria DB
  18. /// </summary>
  19. private void OnSaveExecute()
  20. {
  21. try
  22. {
  23. ClearAllErrors();
  24. _mariaDBModel = new MariaDBModel
  25. {
  26. DBType = "MariaDB",
  27. DSName = DSName,
  28. Description = Description,
  29. IPAddress = IPAddress,
  30. Username = Username,
  31. Password = Password
  32. };
  33.  
  34. var validator = new MariaDBValidator();
  35. ValidationResult result = validator.Validate(_mariaDBModel);
  36. foreach (var error in result.Errors)
  37. {
  38. SetError(error.PropertyName, error.ErrorMessage);
  39. }
  40.  
  41. if (!result.IsValid)
  42. return;
  43.  
  44. _dataController.AddNewDataSet(_mariaDBModel.DSName, _mariaDBModel);
  45. }
  46. finally
  47. {
  48. Logging.For<MariaDBDialog>().Trace("DataSet was saved successfully.");
  49. }
  50. }
  51. #endregion
  52.  
  53. #region Properties
  54. private MariaDBModel _mariaDBModel;
  55. public DelegateCommand SaveCommand { get; private set; }
  56.  
  57. IDataController _dataController = new DataController();
  58.  
  59. private string _dsName;
  60. public string DSName
  61. {
  62. get { return _dsName; }
  63. set { SetProperty(ref _dsName, value); }
  64. }
  65.  
  66. private string _description;
  67. public string Description
  68. {
  69. get { return _description; }
  70. set { SetProperty(ref _description, value); }
  71. }
  72.  
  73. private string _dbType;
  74. public string DBType
  75. {
  76. get { return _dbType; }
  77. set { SetProperty(ref _dbType, value); }
  78. }
  79.  
  80. private string _ipAddress;
  81. public string IPAddress
  82. {
  83. get { return _ipAddress; }
  84. set { SetProperty(ref _ipAddress, value); }
  85. }
  86.  
  87. private string _username;
  88. public string Username
  89. {
  90. get { return _username; }
  91. set { SetProperty(ref _username, value); }
  92. }
  93.  
  94. // Unsafe storage
  95. private string _password;
  96. public string Password
  97. {
  98. get { return _password; }
  99. set { SetProperty(ref _password, value); }
  100. }
  101. #endregion
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement