using Esoft.Windows;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Esoft.Pages
{
    /// <summary>
    /// Логика взаимодействия для ExecutorList.xaml
    /// </summary>
    public partial class ExecutorList : System.Windows.Controls.Page
    {
        private user6Entities _context = new user6Entities();
        //private List<string> listUsers = new List<string>();
        public ExecutorList()
        {
            InitializeComponent();

           
            //CmbExecutorSort.ItemsSource = user6Entities.GetContext().Executor.ToList();


            DGTasks.ItemsSource = user6Entities.GetContext().Task.ToList();

            //foreach (var user in _context.User.ToList())
            //{
            //    listUsers.Add(user.getFamilia());
            //}
            //CmbExecutorSort.ItemsSource = listUsers;

        }

        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new AddExecutor());
        }

        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new AddExecutor());
        }

        private void BtnDelTask_Click(object sender, RoutedEventArgs e)
        {
            var taskIsForRemoving = DGTasks.SelectedItems.Cast<Task>().ToList();
            if (MessageBox.Show($"Вы точно хотите удалить иполнителя?",
                "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    user6Entities.GetContext().Task.RemoveRange(taskIsForRemoving);
                    user6Entities.GetContext().SaveChanges();
                    MessageBox.Show("Данные удалены");
                    DGTasks.ItemsSource = user6Entities.GetContext().Task.ToList();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
            }
        }
    
        }
        
    }


