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;
using System.Globalization;

namespace Agency.Windows
{
    /// <summary>
    /// Логика взаимодействия для Rent.xaml
    /// </summary>
    public partial class Rent : Window
    {
        public Rent()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            gr606_midvlContext context = new gr606_midvlContext();
            var Treaty = context.Treaties;
            var Propirty = context.TheProperties;
            var listPerson = context.ListPeople;
            var Adress = context.Addreses;
            int numAddres = 0;
            int numList = 0;
            Addrese addrese = new Addrese()
            {
                Streat = StratSell.Text,
                HouseNumber = Convert.ToInt32(NumHouse.Text),
                FlatNumber = Convert.ToInt32(NumHouseSell.Text),
                City = CitySell.Text,
            };
            numAddres = addrese.Id;
            Adress.Add(addrese);
            context.SaveChanges();
            TheProperty newProperty = new TheProperty()
            {
                Name = DiscriptSell.Text,
                Area = Convert.ToDouble(AreaSell.Text),
                Rooms = Convert.ToInt32(CollRoomSell.Text),
                PropertyType = TypeSell.Text,
                District = Convert.ToString(RayonSell.Text),
                YearOfConstruction = Convert.ToDateTime(YearOfBuild.Text),
                Floor = Convert.ToInt32(ItazjSell.Text),
                Owner = PersonSave.Id,
                Address = addrese.Id,
                Price = Convert.ToDecimal(PriseSell.Text),
                TypeRent = "Сдаётся",
            };
            int numProperty = newProperty.Id;
            Propirty.Add(newProperty);
            context.SaveChanges();
            ListPerson newListPerson = new ListPerson()
            {
                Idperson = PersonSave.Id,
                Idproperty = newProperty.Id,
            };
            numList = newListPerson.Idlist;
            listPerson.Add(newListPerson);
            context.SaveChanges();
            Treaty treaties = new Treaty()
            {
                PropertyId = newProperty.Id,
                RentalPeriod = Convert.ToInt32(SrocArendi.Text),
                DateOfConclusion = Convert.ToDateTime(DateTime.Now),
                Cost = Convert.ToInt32(PriseSell.Text),
                PersonsInTreaty = newListPerson.Idlist,
            };
            Treaty.Add(treaties);
            context.SaveChanges();
            HomeWindow home = new HomeWindow();
            home.Show();
            this.Hide();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Windows.HomeWindow home = new Windows.HomeWindow();
            home.Show();
            this.Hide();
        }
    }
}
