123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using Rkis29.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Rkis29.Command;
- using Rkis29.Windows;
- using System.Collections.ObjectModel;
- using System.Windows;
- namespace Rkis29.Command
- {
- public class TasksCod : BaseViewModel
- {
- private RelayCommand _YourFind;
- private RelayCommand _StatusUpdate;
- private RelayCommand _TakeTask;
- private RelayCommand _HistoryTask;
- private RelayCommand _FreeTask;
- private ObservableCollection<Task> _tasks = new ObservableCollection<Task>();
- private Task _task;
- private int _count = 0;
- private int _count1 = 0;
- private int _count2 = 0;
- private string _YourLogin;
- public RelayCommand YourFind
- {
- get => _YourFind ??
- (_YourFind = new RelayCommand((x) =>
- {
- _count2++;
- loferlContext loferlcontext = new loferlContext();
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks.Where(p => p.UserCreater.Login == YourLogin));
- if (_count2 % 2 == 0)
- {
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks);
- }
- }));
- }
- public RelayCommand FreeTask
- {
- get => _FreeTask ??
- (_FreeTask = new RelayCommand((x) =>
- {
- _count1++;
- loferlContext loferlcontext = new loferlContext();
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks.Where(p => p.StatusTaskId == 1));
- if (_count1 % 2 == 0)
- {
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks);
- }
- }));
- }
- public RelayCommand HistoryTasks
- {
- get => _HistoryTask ??
- (_HistoryTask = new RelayCommand((x) =>
- {
- _count++;
- loferlContext loferlcontext = new loferlContext();
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks.Where(p => p.StatusTaskId == 3));
- if (_count % 2 == 0)
- {
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks);
- }
- }));
- }
- public RelayCommand TakeTask
- {
- get => _TakeTask ??
- (_TakeTask = new RelayCommand((x) =>
- {
- if (x is Task task)
- {
- if (task.StatusTaskId == 1)
- {
- task.UserTakerId = User.AutoUser.UsersId;
- task.StatusTaskId = 2;
- loferlContext loferlcontext = new loferlContext();
- loferlcontext.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
- task.StatusTask = loferlcontext.Statuses.Find(2);
- loferlcontext.Tasks.Update(task);
- loferlcontext.SaveChanges();
- Tasks = new ObservableCollection<Task>(loferlcontext.Tasks);
- }
- }
- else
- {
- MessageBox.Show("The task is already taken, choose another one.");
- }
- }));
- }
- public RelayCommand StatusUpdate
- {
- get => _StatusUpdate ??
- (_StatusUpdate = new RelayCommand((x) =>
- {
- if (x is Task task)
- {
- if (task.UserCreaterId == User.AutoUser.UsersId)
- {
- loferlContext loferlcontext = new loferlContext();
- loferlcontext.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
- if (task.StatusTaskId == 1)
- {
- task.StatusTaskId = 2;
- task.StatusTask = loferlcontext.Statuses.Find(2);
- loferlcontext.Tasks.Update(task);
- loferlcontext.SaveChanges();
- }
- else if (task.StatusTaskId == 2)
- {
- task.StatusTaskId = 3;
- task.StatusTask = loferlcontext.Statuses.Find(3);
- loferlcontext.Tasks.Update(task);
- loferlcontext.SaveChanges();
- }
- else if (task.StatusTaskId == 3)
- {
- task.StatusTaskId = 1;
- task.StatusTask = loferlcontext.Statuses.Find(1);
- loferlcontext.Tasks.Update(task);
- loferlcontext.SaveChanges();
- }
- }
- else
- {
- MessageBox.Show("You can only change your tasks.");
- }
- }
- }
- ));
- }
- public string YourLogin
- {
- get => _YourLogin;
- set
- {
- _YourLogin = value;
- OnPropertyChanged();
- }
- }
- public ObservableCollection<Task> Tasks
- {
- get => _tasks;
- set
- {
- _tasks = value;
- OnPropertyChanged();
- }
- }
- public Task Task
- {
- get => _task;
- set
- {
- _task = value;
- OnPropertyChanged();
- }
- }
- public TasksCod()
- {
- loferlContext loferlcontext = new loferlContext();
- _tasks = new ObservableCollection<Task>(loferlcontext.Tasks);
- _task = new Task();
- }
- }
- }
|