private void button1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text)) { using (MyContext context = new MyContext()) { string str = Additional.CreateMD5Hash(textBox2.Text); User user = context.Users.Where(x => x.Name == textBox1.Text && x.Password == str && x.Status.Name == "Adminu").SingleOrDefault(); if (user != null) { MessageBox.Show("Hi!!!"); Form1.ActiveForm.Hide(); Work w = new Work(); w.ShowDialog(); Close(); } else { MessageBox.Show("Login or Password is incorect"); } } } }
private void button4_Click(object sender, EventArgs e) { using (MyContext context = new MyContext()) { //Status status = new Status() //{ // Name = "Students" //}; //context.Status.Add(status); //context.SaveChanges(); User person = new User() { Name = textBox1.Text, Password = Additional.CreateMD5Hash(textBox2.Text), StatusId = context.Status.Where(x => x.Name == "Students").Select(x => x.Id).Single() }; context.Users.Add(person); context.SaveChanges(); label3.Visible = true; } }