123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections.ObjectModel;
- using System.Windows;
- namespace Task1.ViewModel
- {
- class TaskWIndowVM : BaseViewModel
- {
- private ObservableCollection<Task> _tasks;
- private Task _task;
- private ObservableCollection<User> _users;
- private User _user;
- private string _LoginUser;
- private RelayCommand _poisk;
- private RelayCommand _change;
- private RelayCommand _end;
- private RelayCommand _update;
- private RelayCommand _dostup;
- private RelayCommand _prinat;
- private RelayCommand _nazad;
- public RelayCommand Nazad
- {
- get
- {
- return _nazad ??
- (_nazad = new RelayCommand((x) =>
- {
- new UserWindow().Show();
- Helper.CloseWindowsAtType<TaskWindow>();
- }));
- }
- }
- public RelayCommand Poisk
- {
- get => _poisk ??
- (_poisk = new RelayCommand((x) =>
- {
- TaskContext taskContext = new TaskContext();
- Tasks = new ObservableCollection<Task>(taskContext.Tasks.Where(a => a.UserCreatedTask.Login == LoginUser));
- }));
- }
- public RelayCommand Dostup
- {
- get => _dostup ??
- (_dostup = new RelayCommand((x) =>
- {
- TaskContext taskContext = new TaskContext();
- Tasks = new ObservableCollection<Task>(taskContext.Tasks.Where(a => a.StatusTaskId == 1));
- }));
- }
- public RelayCommand Update
- {
- get => _update ??
- (_update = new RelayCommand((x) =>
- {
- TaskContext taskContext = new TaskContext();
- Tasks = new ObservableCollection<Task>(taskContext.Tasks);
- }));
- }
- public RelayCommand End
- {
- get => _end ??
- (_end = new RelayCommand((x) =>
- {
- TaskContext taskContext = new TaskContext();
- Tasks = new ObservableCollection<Task>(taskContext.Tasks.Where(a => a.StatusTaskId == 3));
- }));
- }
- public RelayCommand Prinat
- {
- get => _prinat ??
- (_prinat = new RelayCommand((x) =>
- {
- if(x is Task task)
- {
- if(task.StatusTaskId == 1)
- {
- TaskContext taskContext = new TaskContext();
- task.UserAcceptedTaskId = User.AUser.UserId;
- taskContext.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
- task.StatusTaskId = 2;
- task.StatusTask1 = taskContext.StatusTasks.Find(2);
- taskContext.Tasks.Update(task);
- taskContext.SaveChanges();
- }
- else
- {
- MessageBox.Show("Задача занята");
- }
- }
- }));
- }
- public RelayCommand Change
- {
- get => _change ??
- (_change = new RelayCommand((x) =>
- {
- if (x is Task task)
- {
- if (task.UserCreatedTaskId == User.AUser.UserId)
- {
- TaskContext taskContext = new TaskContext();
- taskContext.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
- if (task.StatusTaskId == 1)
- {
- task.StatusTaskId = 2;
- task.StatusTask1 = taskContext.StatusTasks.Find(2);
- taskContext.Tasks.Update(task);
- taskContext.SaveChanges();
- }
- else if (task.StatusTaskId == 2)
- {
- task.StatusTaskId = 3;
- task.StatusTask1 = taskContext.StatusTasks.Find(3);
- taskContext.Tasks.Update(task);
- taskContext.SaveChanges();
- }
- else if (task.StatusTaskId == 3)
- {
- task.StatusTaskId = 1;
- task.StatusTask1 = taskContext.StatusTasks.Find(1);
- taskContext.Tasks.Update(task);
- taskContext.SaveChanges();
- }
- }
- else
- {
- MessageBox.Show("Задача пренадлежит не вам");
- }
- }
- }));
- }
- public string LoginUser
- {
- get => _LoginUser;
- set
- {
- _LoginUser = value;
- OnPropertyChanged();
- }
- }
- public ObservableCollection<Task> Tasks
- {
- get => _tasks;
- set
- {
- _tasks = value;
- OnPropertyChanged();
- }
- }
- public Task Task
- {
- get => _task;
- set
- {
- _task = value;
- OnPropertyChanged();
- }
- }
- public ObservableCollection<User> Users
- {
- get => _users;
- set
- {
- _users = value;
- OnPropertyChanged();
- }
- }
- public User User
- {
- get => _user;
- set
- {
- _user = value;
- OnPropertyChanged();
- }
- }
- public TaskWIndowVM()
- {
- TaskContext taskContext = new TaskContext();
- _tasks = new ObservableCollection<Task>(taskContext.Tasks);
- _task = new Task();
- _users = new ObservableCollection<User>(taskContext.Users);
- _user = new User();
- }
- }
- }
|