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 ProbnikDemo
{
    /// <summary>
    /// Логика взаимодействия для AddAgent.xaml
    /// </summary>
    public partial class AddAgent : Window
    {
        string ImgPath ="";
        public AddAgent()
        {
            InitializeComponent();
            ComboType.ItemsSource = BaseConnect.BaseModel.AgentType.Where(x=>x.ID>0).ToList();
            ComboType.SelectedValuePath = "ID";
            ComboType.DisplayMemberPath = "Title";
           
        }

        private void BtnImg_Click(object sender, RoutedEventArgs e)
        { 

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.DefaultExt = ".jpg";
            openFileDialog.Filter = "Изображения | *.jpg;  *.png";
            var result = openFileDialog.ShowDialog();
            if (result != null)
            {
                ImgPath = openFileDialog.FileName;
                IMG.Source = BitmapFrame.Create(new Uri(openFileDialog.FileName));
            }
        }

        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {


                Agent agent = new Agent() { Title = TxtTitle.Text, Address = TxtAdress.Text, AgentTypeID = Convert.ToInt32(ComboType.SelectedValue), Email = TxtEmail.Text, INN = TxtINN.Text, KPP = TxtKPP.Text, Priority = Convert.ToInt32(TxtPriority.Text), Logo = ImgPath, Phone = TxtPhone.Text, DirectorName = TxtDirector.Text };
                BaseConnect.BaseModel.Agent.Add(agent);
                BaseConnect.BaseModel.SaveChanges();
                LoadPages.SwitchPages.Navigate(new PgListAgent());
            }
            catch
            {
                MessageBox.Show("Ошибка");
            }

        }
    }
}
