using Database.Repository;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace Pos.Setting.ProductGroup
{
    /// <summary>
    /// Interaction logic for AddProductWindow.xaml
    /// </summary>
    public partial class AddProductWindow : Window
    {
        public AddProductWindow()
        {
            InitializeComponent();
            LoadData(0);
        }

        private void LoadData(int selectedIndex)
        {
            ProductGroupRepository productGroupRepository = new ProductGroupRepository();
            List<Database.Models.ProductGroupEntity> products = productGroupRepository.GetAll();
            foreach (Database.Models.ProductGroupEntity productGroup in products)
            {
                ComboBoxItem comboBoxItem = new ComboBoxItem();
                comboBoxItem.Tag = productGroup.Id;
                comboBoxItem.Content = productGroup.Name;
                cmbProductGroup.Items.Add(comboBoxItem);
            }

            cmbProductGroup.SelectedIndex = selectedIndex;
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            ComboBoxItem item = (ComboBoxItem) cmbProductGroup.SelectedItem;
            string name = txtProduct.Text;
            int id = Convert.ToInt32(item.Tag);
            ProductRepository productRepository = new ProductRepository();
            productRepository.Add(name,id);
            this.Close();
        }
    }
}
