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.Navigation;
using System.Windows.Shapes;

namespace Logistics_application
{
    /// <summary>
    /// Логика взаимодействия для SenderList.xaml
    /// </summary>
    public partial class SenderList : Page
    {
        gr682_ggi3Entities1 db = new gr682_ggi3Entities1();
        public SenderList()
        {
            InitializeComponent();
        }

        private void Insert_Click(object sender, RoutedEventArgs e)
        {
            Sender senderT = new Sender();
            senderT.Surname = txtSurname.Text;
            senderT.Name = txtName.Text;
            senderT.MiddleName = txtMiddleName.Text;
            senderT.PhoneNumber = txtPhoneNumber.Text;
            senderT.City = txtCity.Text;
            db.Sender.Add(senderT);
            db.SaveChanges();
            table.ItemsSource = db.Sender.ToList();
        }

        private void Update_Click(object sender, RoutedEventArgs e)
        {
            int num = Convert.ToInt32(txtID.Text);
            var uRow = db.Sender.Where(w => w.ID_Sender == num).FirstOrDefault();
            uRow.Surname = txtSurname.Text;
            uRow.Name = txtName.Text;
            uRow.MiddleName = txtMiddleName.Text;
            uRow.PhoneNumber = txtPhoneNumber.Text;
            uRow.City = txtCity.Text;
            db.SaveChanges();
            table.ItemsSource = db.Sender.ToList();
        }

        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            int num = Convert.ToInt32(txtID.Text);
            var dRow = db.Sender.Where(w => w.ID_Sender == num).FirstOrDefault();
            db.Sender.Remove(dRow);
            db.SaveChanges();
            table.ItemsSource = db.Sender.ToList();
        }
    }
}
