Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GalaSoft.MvvmLight;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- using Tabs.ViewModel.Base;
- using URE.Models;
- namespace URE_MVVM.ViewModel
- {
- public class UsersTabViewModel : ViewModelBase
- {
- //private ObservableCollection<User> users;
- private ObservableCollection<User> users;
- private ICommand addUserCommand;
- private ICommand removeUserCommand;
- private string id;
- private string username;
- private string login;
- private string password;
- private string group;
- private bool _canExecute;
- public UsersTabViewModel()
- {
- _canExecute = true;
- Users = new ObservableCollection<User>();
- }
- public ObservableCollection<User> Users { get; set; }
- public string Id
- {
- get
- {
- return id;
- }
- set
- {
- id = value;
- }
- }
- public string Username
- {
- get
- {
- return username;
- }
- set
- {
- if (!string.Equals(this.username, value))
- {
- this.username = value;
- this.RaisePropertyChanged();
- }
- }
- }
- public string Login
- {
- get
- {
- return login;
- }
- set
- {
- if (!string.Equals(this.login, value))
- {
- this.login = value;
- this.RaisePropertyChanged();
- }
- }
- }
- public string Password
- {
- get
- {
- return password;
- }
- set
- {
- if (!string.Equals(this.password, value))
- {
- this.password = value;
- this.RaisePropertyChanged();
- }
- }
- }
- public string Group
- {
- get
- {
- return group;
- }
- set
- {
- if (!string.Equals(this.group, value))
- {
- this.group = value;
- this.RaisePropertyChanged();
- }
- }
- }
- private void RemoveUserAction()
- {
- ObservableCollection<User> tempUsers = new ObservableCollection<User>(this.Users);
- foreach (User user in tempUsers){
- }
- }
- private void AddUserAction()
- {
- //Text = "Text";
- //add user
- //Users.Add(new User(1,"name","gg","gg","group"));
- Users.Add(new User(Int32.Parse(Id), Username, Login,Password, Group));
- }
- public ICommand AddUserCommand
- {
- get
- {
- return addUserCommand ?? (addUserCommand = new CommandHandler(() => AddUserAction(), _canExecute));
- }
- }
- public ICommand RemoveUserCommand
- {
- get
- {
- return removeUserCommand ?? (removeUserCommand = new CommandHandler(() => RemoveUserAction(), _canExecute));
- }
- }
- public class CommandHandler : ICommand
- {
- private Action _action;
- private bool _canExecute;
- public CommandHandler(Action action, bool canExecute)
- {
- _action = action;
- _canExecute = canExecute;
- }
- public bool CanExecute(object parameter)
- {
- return _canExecute;
- }
- public event EventHandler CanExecuteChanged;
- public void Execute(object parameter)
- {
- _action();
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- }
- }
Add Comment
Please, Sign In to add comment