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.Shapes;
using DemoexamUser11.classes;

namespace DemoexamUser11.windows
{
    /// <summary>
    /// Логика взаимодействия для WindowChangePriority.xaml
    /// </summary>
    public partial class WindowChangePriority : Window
    {
        List<Agent> agents;
        public WindowChangePriority(List<Agent> agents)
        {
            InitializeComponent();
            this.agents = agents;
            agents.Sort(delegate (Agent a1, Agent a2)
            {
                return a1.Priority.CompareTo(a2.Priority);
            });
            textBoxValue.Text = agents.Last().Priority.ToString();
        }

        private void buttonBack_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxValue.Text.Replace(" ", "") != "")
            {
                try
                {
                    foreach (Agent agent in agents)
                    {
                        BaseConnector.BaseConnect.Agent.FirstOrDefault(x => x.ID == agent.ID).Priority = Convert.ToInt32(textBoxValue.Text);
                    }
                    MessageBox.Show("Успех!");
                }
                catch
                {
                    MessageBox.Show("Не удалось изменить приоритеты! Введите число");
                }
                
            }
        }
    }
}
