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;

namespace Session1
{
    /// <summary>
    /// Логика взаимодействия для ChangePriority.xaml
    /// </summary>
    public partial class ChangePriority : Window
    {
        List<Agent> selectedAgents = new List<Agent>();
        public ChangePriority(List<Agent> selectedAgents)
        {
            InitializeComponent();
            this.selectedAgents = selectedAgents;
            priorityBox.Text = selectedAgents.OrderByDescending(x => x.Priority).First().Priority.ToString();
        }

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

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            foreach(Agent agent in selectedAgents)
            {
                BaseConnect.baseModel.Agent.Where(x => x.ID == agent.ID).First().Priority = Convert.ToInt32(priorityBox.Text);
            }
            try
            {
                BaseConnect.baseModel.SaveChanges();
                MessageBox.Show("Данные успешно сохранены");
                Close();
            }
            catch
            {
                MessageBox.Show("Не удалось записать данные в базу");
            }
        }
    }
}
