private void btnIssueTicket_Click(object sender, RoutedEventArgs e) { string br = ""; if (chbSendEmail.IsChecked.Value) { if (txtEmail.Text.Trim() == "") { MessageBox.Show("Enter email to receive booking information", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!Regex.IsMatch(txtEmail.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")) { MessageBox.Show("Email is invalid", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } br = GetBr(); //Send mail string bookingInfor = $"Booking reference: {br}\n\n" + GetBookingInformation(Tickets); try { MailProcessing.SendMail(txtEmail.Text, "Your booking information from AMONIC Airline:", bookingInfor); } catch (System.Exception) { MessageBox.Show("Please connect to the internet!", "Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } } br = br == "" ? GetBr() : br; foreach (var item in Tickets) { item.BookingReference = br; Db.Context.Tickets.Add(item); } Db.Context.SaveChanges(); IsConfirm = true; if (chbSendEmail.IsChecked.Value) { MessageBox.Show("Issue ticket successful\nBooking information was sent to passenger's email", "Message", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Issue ticket successful", "Message", MessageBoxButton.OK, MessageBoxImage.Information); } this.Close(); }
//////////////////////////////////////////////////// /// <summary> /// Gets the data and email result. /// </summary> /// <param name="toEmail">To email.</param> /// <param name="name">The name.</param> /// <param name="ageFrom">The age from.</param> /// <param name="ageTo">The age to.</param> /// <param name="heightFrom">The height from.</param> /// <param name="heightTo">The height to.</param> /// <param name="weightFrom">The weight from.</param> /// <param name="weightTo">The weight to.</param> /// <param name="nationalityId">The nationality identifier.</param> private void GetDataAndEmailResult(string toEmail, string name, int?ageFrom, int?ageTo, int?heightFrom, int?heightTo, int?weightFrom, int?weightTo, int?nationalityId) { //prepare CriminalSearchParameter and send tp service var service = new CriminalProfileService(unitOfWork, new CriminalProfileRepository()); var profiles = service.Search(new CriminalSearchParameter() { Name = name, AgeFrom = ageFrom, AgeTo = ageTo, HeightFrom = heightFrom, HeightTo = heightTo, WeightFrom = weightFrom, WeightTo = weightTo, NationalityId = nationalityId }); //var profiles = service.GetAll(); var attachements = PDFProcessing.ExportDataToPdfFromTemplate(profiles.ToList()); MailProcessing.sendMail(toEmail, attachements); }