void clear() { TxtId.Clear(); TxtNameUser.Clear(); TxtApellido.Clear(); TxtEdad.Clear(); TxtPass.Clear(); }
private void btnSubmitUser_Click(object sender, RoutedEventArgs e) { var res = myContext.Users.FirstOrDefault(dataInMail => dataInMail.Email == TxtEmailUser.Text); if (TxtNameUser.Text == "") { MessageBox.Show("Fill column name please", "Alert", MessageBoxButton.OK); TxtNameUser.Focus(); } else if (TxtEmailUser.Text == "") { MessageBox.Show("Fill column email please", "Alert", MessageBoxButton.OK); TxtEmailUser.Focus(); } else if (res != null) { MessageBox.Show("This email already registered", "Alert", MessageBoxButton.OK); TxtEmailUser.Focus(); } else { var role = myContext.Roles.FirstOrDefault(r => r.Id == roleid); password = Guid.NewGuid().ToString(); var push = new User(TxtNameUser.Text, TxtEmailUser.Text, password, role); myContext.Users.Add(push); var result = myContext.SaveChanges(); if (result > 0) { try { //MailAddress from = new MailAddress("*****@*****.**", "Name and stuff"); //MailAddress to = new MailAddress(TxtEmailUser.Text, "Name and stuff"); //List<MailAddress> cc = new List<MailAddress>(); //cc.Add(new MailAddress(TxtEmailUser.Text, "Name and stuff")); //SendEmail("Login Successful", from, to, cc); Outlook._Application _app = new Outlook.Application(); Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem); //sesuaikan dengan content yang di xaml mail.To = TxtEmailUser.Text; mail.Subject = "Bootcamp 32"; mail.Body = "Congratulations, " + TxtNameUser.Text + " has been registered\nThis is your password: "******"Message has been sent.", "Message", MessageBoxButton.OK); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButton.OK); } } } }