using System;
using System.Linq;
using System.Windows;

namespace Hotel_Course_Project
{
    /// <summary>
    /// Логика взаимодействия для PayAddOnOrderWindow.xaml
    /// </summary>
    public partial class PayAddOnOrderWindow : Window
    {
        public int _numDays;
        public decimal _costPerDay;
        public PayAddOnOrderWindow(int numDays, decimal costPerDay)
        {
            InitializeComponent();
            _numDays = numDays;
            _costPerDay = costPerDay;
            SummEnd.Text = (_numDays * _costPerDay).ToString();
            SPayTypeCB.ItemsSource = DataBase.db.PayType.ToList();
        }

        private void BackBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            int idPayType = DataBase.db.PayType.SingleOrDefault(item => item.Name == SPayTypeCB.Text).Id;
            Pay pay = new Pay()
            {
                EndSum = _numDays * _costPerDay,
                Id_PayType = idPayType,
                PayDate = DateTime.Now.Date
            };
            DataBase.db.Pay.Add(pay);
            Helper.pay = pay;
            var lastId = DataBase.db.Pay.OrderByDescending(item => item.Id).FirstOrDefault().Id;
            DataBase.db.SaveChanges();
            Helper.idNewPay = lastId;
            DialogResult = true;
        }
    }
}
