Guest User

Untitled

a guest
Dec 24th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.31 KB | None | 0 0
  1. using GalaSoft.MvvmLight;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Input;
  10. using Tabs.ViewModel.Base;
  11. using URE.Models;
  12.  
  13. namespace URE_MVVM.ViewModel
  14. {
  15.     public class UsersTabViewModel : ViewModelBase
  16.     {
  17.         //private ObservableCollection<User> users;
  18.         private ObservableCollection<User> users;
  19.         private ICommand addUserCommand;
  20.         private ICommand removeUserCommand;
  21.  
  22.         private string id;
  23.         private string username;
  24.         private string login;
  25.         private string password;
  26.         private string group;
  27.  
  28.  
  29.         private bool _canExecute;
  30.  
  31.         public UsersTabViewModel()
  32.         {
  33.             _canExecute = true;
  34.             Users = new ObservableCollection<User>();
  35.         }
  36.  
  37.         public ObservableCollection<User> Users { get; set; }
  38.      
  39.         public string Id
  40.         {
  41.             get
  42.             {
  43.                 return id;
  44.             }
  45.  
  46.             set
  47.             {
  48.                 id = value;
  49.             }
  50.         }
  51.         public string Username
  52.         {
  53.             get
  54.             {
  55.                 return username;
  56.             }
  57.  
  58.             set
  59.             {
  60.                
  61.                 if (!string.Equals(this.username, value))
  62.                 {
  63.                     this.username = value;
  64.                     this.RaisePropertyChanged();
  65.                 }
  66.             }
  67.         }
  68.  
  69.         public string Login
  70.         {
  71.             get
  72.             {
  73.                 return login;
  74.             }
  75.  
  76.             set
  77.             {
  78.                 if (!string.Equals(this.login, value))
  79.                 {
  80.                     this.login = value;
  81.                     this.RaisePropertyChanged();
  82.                 }              
  83.             }
  84.         }
  85.  
  86.         public string Password
  87.         {
  88.             get
  89.             {
  90.                 return password;
  91.             }
  92.  
  93.             set
  94.             {
  95.                 if (!string.Equals(this.password, value))
  96.                 {
  97.                     this.password = value;
  98.                     this.RaisePropertyChanged();
  99.                 }
  100.             }
  101.         }
  102.  
  103.         public string Group
  104.         {
  105.             get
  106.             {
  107.                 return group;
  108.             }
  109.  
  110.             set
  111.             {
  112.                 if (!string.Equals(this.group, value))
  113.                 {
  114.                     this.group = value;
  115.                     this.RaisePropertyChanged();
  116.                 }
  117.             }
  118.         }
  119.  
  120.  
  121.  
  122.         private void RemoveUserAction()
  123.         {
  124.  
  125.             ObservableCollection<User> tempUsers = new ObservableCollection<User>(this.Users);
  126.  
  127.             foreach (User user in tempUsers){
  128.                
  129.             }
  130.         }
  131.  
  132.         private void AddUserAction()
  133.         {
  134.             //Text = "Text";
  135.             //add user
  136.             //Users.Add(new User(1,"name","gg","gg","group"));
  137.             Users.Add(new User(Int32.Parse(Id), Username, Login,Password, Group));
  138.         }
  139.  
  140.  
  141.         public ICommand AddUserCommand
  142.         {
  143.             get
  144.             {
  145.                 return addUserCommand ?? (addUserCommand = new CommandHandler(() => AddUserAction(), _canExecute));
  146.             }
  147.  
  148.         }
  149.  
  150.         public ICommand RemoveUserCommand
  151.         {
  152.             get
  153.             {
  154.                 return removeUserCommand ?? (removeUserCommand = new CommandHandler(() => RemoveUserAction(), _canExecute));
  155.             }
  156.         }
  157.  
  158.        
  159.  
  160.         public class CommandHandler : ICommand
  161.         {
  162.             private Action _action;
  163.             private bool _canExecute;
  164.             public CommandHandler(Action action, bool canExecute)
  165.             {
  166.                 _action = action;
  167.                 _canExecute = canExecute;
  168.             }
  169.  
  170.             public bool CanExecute(object parameter)
  171.             {
  172.                 return _canExecute;
  173.             }
  174.  
  175.             public event EventHandler CanExecuteChanged;
  176.  
  177.             public void Execute(object parameter)
  178.             {
  179.                 _action();
  180.             }
  181.         }
  182.  
  183.  
  184.  
  185.  
  186.  
  187.         public event PropertyChangedEventHandler PropertyChanged;
  188.     }
  189. }
Add Comment
Please, Sign In to add comment