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

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DiscriptSell.Text != "" && AreaSell.Text != "" && CollRoomSell.Text != "" && TypeSell.Text != "" && YearOfBuild.Text != "" && ItazjSell.Text != "" && StratSell.Text != "" && NumHouse.Text != "" && NumHouseSell.Text != "" && PriceSell.Text != "")
            {
                gr606_midvlContext context = new gr606_midvlContext();
                var sellProperty = context.TheProperties;
                var sellAddress = context.Addreses;

                Addrese address = new Addrese()
                {
                    Streat = StratSell.Text,
                    HouseNumber = Convert.ToInt32(NumHouse.Text),
                    FlatNumber = Convert.ToInt32(NumHouseSell.Text),
                    City = CitySell.Text,
                };
                context.Add(address);
                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,
                    Price = Convert.ToDecimal(PriceSell.Text),
                    Address = address.Id,
                    TypeRent = "Продаётся",
                };               
                context.Add(newProperty);
                context.SaveChanges();
                HomeWindow homeWindow = new HomeWindow();

                homeWindow.Show();
                this.Hide();
            }
        }

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