public IActionResult ContactMe(ContactMeMessage viewModel) { if (!ModelState.IsValid) { return(View("Partials/_ContactPartial", viewModel)); } _emailService.ContactMe(viewModel.Name, viewModel.Email, viewModel.Message); return(RedirectToAction(nameof(Index))); }
public void AddMessage(ContactMeMessage m) { Cmd.CommandText = "insert into dbo.ContactMe values (@Name, @Email, @Message)"; Cmd.Parameters.Clear(); Cmd.Parameters.AddWithValue("@Name", m.Name); Cmd.Parameters.AddWithValue("@Email", m.Email); Cmd.Parameters.AddWithValue("@Message", m.Message); try { Con.Open(); Cmd.ExecuteNonQuery(); } catch (Exception e) { logger.Error(e.StackTrace); Console.WriteLine("Inserting into dbo.ContactMe failed!"); } finally { Con.Close(); } }