using System;
using System.Collections;
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 ShabaninDemoEkz
{
    /// <summary>
    /// Логика взаимодействия для ChangedPrior.xaml
    /// </summary>
    public partial class ChangedPrior : Window
    {
        IList lss;
        VModel VM = new VModel();
        List<Agent> agents;
        public ChangedPrior(IList ls)
        {
            InitializeComponent();
            lss = ls;
            agents = VM.agent;

            List<int> i = new List<int>();
            foreach (Agent a in ls)
            {
                i.Add(a.Priority);
            }
            priorTxt.Text = i.Max().ToString();

        }

        public void changed()
        {


            foreach (Agent a in lss)
            {
                foreach (Agent aa in agents)
                {
                    if (a.ID == aa.ID)
                    {
                        aa.Priority = Convert.ToInt32(priorTxt.Text);
                    }
                }
            }

        }

        private void SaveP_Click(object sender, RoutedEventArgs e)
        {
            if (Convert.ToInt32(priorTxt.Text) > 0 && priorTxt.Text != "")
            {
                MessageBoxResult dialogResult = MessageBox.Show("Сохранить?", "Сохранение", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    changed();
                    BaseConnect.BaseModel.SaveChanges();
                    MessageBox.Show("Изменения сохранены", "Сохранение изменений", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("Неверный формат приоритета", "Ошибка формата", MessageBoxButton.OK, MessageBoxImage.Error);

            }


        }
    }
}
