using Microsoft.Win32;
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>
    /// Логика взаимодействия для AddAgent.xaml
    /// </summary>
    public partial class AddAgent : Window
    {
        public AddAgent()
        {
            InitializeComponent();
        }

        private void save_Click(object sender, RoutedEventArgs e)
        {
            Agent newAgent = new Agent();
            newAgent.Logo = imgPath.Text = newAgent.Logo;
            newAgent.Title = agentName.Text;
            newAgent.AgentTypeID = ((AgentType)agentType.SelectedItem).ID;
            newAgent.Priority = Convert.ToInt32(agentPriority.Text);
            newAgent.Address = agentAddress.Text;
            newAgent.INN = agentINN.Text;
            newAgent.KPP = agentKPP.Text;
            newAgent.Phone = agentPhone.Text;
            newAgent.DirectorName = agentDirector.Text;
            newAgent.Email = agentEmail.Text;
            try
            {
                BaseConnect.baseModel.SaveChanges();
                MessageBox.Show("Данные успешно изменены.");
                Close();
            }
            catch
            {
                MessageBox.Show("Не удалось изменить данные.");
            }
        }

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

        private void addImage_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "*.jpg | *.png";
            openFileDialog.ShowDialog();
            string filePath = openFileDialog.FileName;
            imgPath.Text = filePath;
        }
    }
}
