private async Task SendMail(StringCalculatorViewModel content) { const string MAIL_HOST = "localhost"; const int MAIL_PORT = 1025; var message = new MimeMessage(); message.From.Add(new MailboxAddress("CICD Web Application", "*****@*****.**")); message.To.Add(new MailboxAddress("Student", "*****@*****.**")); message.Subject = "Your calculated Sum"; message.Body = new TextPart("plain") { Text = $"Hello, your calculation result: sum of {content.Input} = {content.Sum} " + $"{(content.Error != String.Empty ? $"\n\nError: {content.Error} " : "")}" }; using (var mailClient = new SmtpClient()) { await mailClient.ConnectAsync(MAIL_HOST, MAIL_PORT, SecureSocketOptions.None); await mailClient.SendAsync(message); await mailClient.DisconnectAsync(true); content.EmailIsSent = true; } }
public async Task <IActionResult> Email(string input) { StringCalculatorViewModel calculationResult = CalculateSum(input); await SendMail(calculationResult); return(View("Index", calculationResult)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { Scvm = new StringCalculatorViewModel(calcGraph.Height, calcGraph.Width); void SetDataContext() { calcGraph.Children.Add(Scvm.XaxisPath); calcGraph.Children.Add(Scvm.YaxisPath); calcGraph.Children.Add(Scvm.DatasetPoly); } SetDataContext(); InitializeComponent(); _bw = new BackgroundWorker(); _bw.DoWork += new DoWorkEventHandler(_bw_DoWork); _bw.RunWorkerAsync(); this.DataContext = Scvm; }
private StringCalculatorViewModel CalculateSum(string input) { StringCalculatorViewModel scvm = new StringCalculatorViewModel { Input = input }; try { StringCalculator stringCalculator = new StringCalculator(); int sum = stringCalculator.Add(input); scvm.Sum = sum; } catch (Exception ex) { scvm.Sum = 0; scvm.Error = ex.Message; } return(scvm); }
public IActionResult Calculate(string input) { StringCalculatorViewModel calculationResult = CalculateSum(input); return(View("Index", calculationResult)); }