using ExcelExample.Entites;
using ExcelExample.Context;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace LoadingExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                using (var db = new MyDB())
                {
                    if (!db.Database.GetService<IRelationalDatabaseCreator>().Exists())
                    {
                        await db.Database.EnsureCreatedAsync();
                       
                        List<User> users = new List<User>();
                        users.Add(new User() { Email = "test1@gmail.com", family = "رضا", Name = "حسینی", number = "09360000000" });
                        users.Add(new User() { Email = "test2@gmail.com", family = "علی", Name = "محمدی", number = "09360000000" });
                        users.Add(new User() { Email = "test3@gmail.com", family = "محمد", Name = "علی پور", number = "09360000000" });
                        users.Add(new User() { Email = "test4@gmail.com", family = "حسین", Name = "رضایی", number = "09360000000" });
                        users.Add(new User() { Email = "test5@gmail.com", family = "حسن", Name = "جعفری", number = "09360000000" });
                        foreach (var user in users)
                        {
                            db.users.Add(user);
                            db.SaveChanges();

                        }
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "خطا");
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {

            DataForm dataForm = new DataForm();
            dataForm.ShowDialog();
        }


    }
}