public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } try { // email to support email string supportEmailBody = await RazorRenderer.RenderPartialToStringAsync("_SupportEmailTemplate", Contact); await Mailer.SendEmailAsync( _supportEmailSettings.SupportEmailAddress, _supportEmailSettings.AdministratorName, "Client Information - Arsha.Dev", supportEmailBody); _logger.Log(LogLevel.Information, $"Sent email to the support email"); //email to the client string thankYouBody = await RazorRenderer.RenderPartialToStringAsync("_ThankYou", Contact); await Mailer.SendEmailAsync(Contact.Email, Contact.Name, "Thank You - Arsha.Dev", thankYouBody); _logger.Log(LogLevel.Information, "Sent email to the client email"); } catch (Exception e) { _logger.Log(LogLevel.Error, $"Email operation failed: {e.Message}"); } return(RedirectToPage("Index")); }
public async Task <ContentResult> OnPostRunAsync() { if (bd_config.get(bd_config.DebugEnableRunSql) == 0) { return(Content("<div>DebugEnableRunSql: 0</div>")); } dt = null; error = null; try { dt = bd_db.get_datatable(sql); } catch (Exception e) { if (e.Message == "Cannot find table 0.") { // suppress this - this is just what happens when we run a query that does't SELECT // like an update success = "Success"; } else { error = e.Message; } } String html = await _renderer.RenderPartialToStringAsync("_PlainDataTablePartial", this); return(Content(html)); }
public async void SendNotification(StudentDataEntry entry, bool created) { if (string.IsNullOrEmpty(entry.Student.NotificationEmail)) { return; } var user = database.Users .Include(u => u.Groups) .ThenInclude(g => g.GradeLevel) .Single(u => u.Id == entry.Student.Id); if (!CanSendNotification(user.Groups.Single(g => g.GroupType == GroupType.Class).GradeLevel, entry, created)) { return; } var settings = databaseProperties.GetProperty <EmailSettings>(); var body = await partialToStringRenderer.RenderPartialToStringAsync("EmailPage", new EmailPage { Text = $"{entry} was added" }); var message = new MimeMessage(); message.From.Add(new MailboxAddress("SmartGrade", settings.SenderAddress)); message.To.Add(new MailboxAddress(string.Empty, entry.Student.NotificationEmail)); message.Subject = "Test Header"; message.Body = new TextPart("html") { Text = body }; ThreadPool.QueueUserWorkItem(o => SendEmail(message)); }
public async Task <IActionResult> SendReminderEmailForAllEvents( [FromQuery] PagingOptions pagingOptions, [FromQuery] SortOptions <Event, EventEntity> sortOptions, [FromQuery] SearchOptions <Event, EventEntity> searchOptions, CancellationToken ct) { pagingOptions.Offset = pagingOptions.Offset ?? _defaultPagingOptions.Offset; pagingOptions.Limit = pagingOptions.Limit ?? _defaultPagingOptions.Limit; var events = await _event.GetAllAsync(pagingOptions, sortOptions, searchOptions, ct); foreach (var @event in events.Items) { foreach (var participant in @event.Participant.Where(x => !x.IsFeedbackReceived)) { var feedbackType = participant.Attended ? "participated" : participant.NotAttended ? "notparticipated" : "unregistered"; var emailModel = new FeedbackRequestEmailTemplateModel { EventName = @event.EventName, EventDate = @event.EventDate.ToShortDateString(), ParticipantName = participant.EmployeeName, FeedbackUrl = $"{_configuration.GetSection("EmailUrl").Value}/feedback/{feedbackType}/{@event.Id}/{participant.Id}" }; var body = await _renderer.RenderPartialToStringAsync("_FeedbackRequestEmailPartial", emailModel); await _emailService.SendAsync(User.Identity.Name, "Admin", participant.EmployeeId, $"Feedback Requested for {@event.EventName} at {@event.EventDate}", body); } } return(Ok()); }
public async Task <ActionResult> OnGetLoadMoreAsync(int pageNumber) { // set default page size, it should be set in admin page // for testing, set here int pagesize = 5; var posts = await _blogService.GetAllBlogPostsAsync(pageNumber : pageNumber, pageSize : 5); var list = new List <BlogPostListRowViewModel>(); foreach (var post in posts) { var item = new BlogPostListRowViewModel { Slug = post.Title, AuthorName = "Xuan Nguyen", Title = post.Title, BodyOverview = post.BodyOverview, CreatedOnUtc = post.CreatedOnUtc, }; item.Tags.Add(new BlogPostListRowViewModel.Tag { Slug = "fdaf-dfadfa", Name = "test" }); list.Add(item); } PostListPartialViewModel partialViewModel = new PostListPartialViewModel(); partialViewModel.NoMoredata = list.Count < pagesize; partialViewModel.HtmlString = await _razorPartialToStringRenderer.RenderPartialToStringAsync("_PostListPartial", list); return(new JsonResult(partialViewModel)); }
public async Task <IActionResult> CreateReminderEmail([FromBody] ReminderEmailForm form) { var userId = await _user.GetUserIdAsync(User); if (userId == null) { return(NotFound()); } var @event = await _event.FindAsync(form.EventId, CancellationToken.None); foreach (var participant in @event.Participant.Where(x => !x.IsFeedbackReceived)) { var feedbackType = participant.Attended ? "participated" : participant.NotAttended ? "notparticipated" : "unregistered"; var emailModel = new FeedbackRequestEmailTemplateModel { EventName = @event.EventName, EventDate = @event.EventDate.ToShortDateString(), ParticipantName = participant.EmployeeName, FeedbackUrl = $"{_configuration.GetSection("EmailUrl").Value}/feedback/{feedbackType}/{@event.Id}/{participant.Id}" }; var body = await _renderer.RenderPartialToStringAsync("_FeedbackRequestEmailPartial", emailModel); await _emailService.SendAsync(User.Identity.Name, "Admin", participant.EmployeeId, $"Feedback Requested for {@event.EventName} at {@event.EventDate}", body); } return(Ok()); }
public async Task <IActionResult> OnPostAsync() { var body = await _renderer.RenderPartialToStringAsync("Emails/ContactEmailPartial", ContactForm); await _emailSender.SendEmailAsync(ContactForm.Email, ContactForm.Subject, body); PostResult = "Check your specified pickup directory"; return(RedirectToPage()); }
private async Task <bool> GeneratePageConstructionModel() { UserTeamTableModel dummyUserTeamTableModel = new UserTeamTableModel() { userProfileModel = GenerateDummyUserProfileModel(), StatusList = StatusList, TeamSelectList = userTeamTableModel.TeamSelectList }; var teamListHTML = await _renderer.RenderPartialToStringAsync("_UserTeamList", dummyUserTeamTableModel); teamListHTML = teamListHTML.Replace("\n", "").Replace("\r", "").Replace("\t", "").ToString(); var teamTableHTML = _renderer.GetStringBetween(teamListHTML, "<!--TeamTableRowsStart-->", "<!--TeamTableRowsEnd-->"); List <string> teamListRows = teamTableHTML.TrimStart().TrimEnd().Replace("<td>", "").Split("</td>").ToList(); for (int i = teamListRows.Count - 1; i >= 0; i--) { var eol = ","; teamListRows[i] = teamListRows[i].TrimStart().TrimEnd(); if (string.IsNullOrWhiteSpace(teamListRows[i])) { teamListRows.RemoveAt(i); continue; } if (i == teamListRows.Count - 1) { eol = ""; } teamListRows[i] = teamListRows[i].Replace("userProfileModel_userTeamJoins_0__", "userProfileModel_userTeamJoins_' + rowCount + '__"); teamListRows[i] = teamListRows[i].Replace("userProfileModel.userTeamJoins[0]", "userProfileModel.userTeamJoins[' + rowCount + ']"); teamListRows[i] = teamListRows[i].Replace("22222222-2222-2222-2222-222222222222", "' + userId + '"); teamListRows[i] = teamListRows[i].Replace("disabled", string.Empty); //Prevent the team drop down from being disabled on new rows teamListRows[i] = $"'{teamListRows[i]}'{eol}"; } userTeamTableModel.teamListRows = teamListRows.ToArray(); return(true); }
// Same as RunSql.cshmtl.cs but tries to detect sql that does an update // No promises though. You need to trust your admins. public async Task <ContentResult> OnPostRunAsync() { dt = null; error = null; if (string.IsNullOrWhiteSpace(sql)) { error = "Sql is required."; } else { // sql is not blandb string dangerous_word = bd_util.find_dangerous_words_in_sql(sql); if (dangerous_word is not null) { error = "Dangerous keyword not allowed (see Budoco DangerousSqlKeywords setting): " + dangerous_word; } else { // sql has no dangerous words, so try to run try { sql = bd_util.enhance_sql_per_user(HttpContext, sql); dt = bd_db.get_datatable(sql); } catch (Exception e) { if (e.Message == "Cannot find table 0.") { // suppress this - this is just what happens when we run a query that does't SELECT // like an update success = "Success"; } else { error = e.Message; } } } } String html = await _renderer.RenderPartialToStringAsync("_PlainDataTablePartial", this); return(Content(html)); }
public async Task <ContentResult> OnGetPostsAsync() { time1 = DateTime.Now; // client fetches posts using ajax //check permission organization_id = (int)bd_db.exec_scalar( "select i_organization from issues where i_id = " + id.ToString()); // A user wouldn't normally get this far, to be able to post // unless his permission was changed from under him or he was hacking if (!GetAndCheckUserOrg(organization_id)) { return(Content("<!--error--><!--org permission-->")); } // get posts var sql = @"select posts.*, us_username from posts inner join users on us_id = p_created_by_user where p_issue = " + id.ToString() + " order by p_id asc"; dt_posts = bd_db.get_datatable(sql); // get the html as a string and return it to ajax client String html = await _renderer.RenderPartialToStringAsync("_IssuePostsPartial", this); time2 = DateTime.Now; TimeSpan timespan = time2 - time1; bd_util.log("OnGetPostsAsync milliseconds:" + timespan.TotalMilliseconds.ToString()); if (post_error != "") { return(Content("<!--error-->" + html)); } else { return(Content(html)); } }
public async Task SendActivateUserMailAsync(string tenantId, User user) { var foundUser = await _userService.FindOneAsync(user.Id !); if (foundUser == null) { _logger.LogError($"User '{user.Id}' not found"); return; } var tenant = await TenantTools.SearchTenantByIdAsync(_logger, _sl, _tenantCacheService, _daprClient, tenantId); var secretValues = await _daprClient.GetSecretAsync(ConfigConstant.CodexKey, ConfigConstant.BackOfficeUrl); var backOfficeUrl = secretValues[ConfigConstant.BackOfficeUrl]; secretValues = await _daprClient.GetSecretAsync(ConfigConstant.CodexKey, ConfigConstant.SenderEmail); var mailSenderEmail = secretValues[ConfigConstant.SenderEmail]; UriBuilder uriBuilder = new(scheme : "https", backOfficeUrl, 443, $"activate/{user.Id}"); var parameters = HttpUtility.ParseQueryString(string.Empty); parameters["activationCode"] = user.ActivationCode; uriBuilder.Query = parameters.ToString(); string activationLink = uriBuilder.Uri.ToString(); UserNameActivationModel model = new(tenant, user, activationLink); string subject = "Activation de votre compte"; string htmlPart = await _razorPartialToStringRenderer.RenderPartialToStringAsync("/Templates/_ActivateUserTemplate.cshtml", model); await _mailService.SendEmailAsync(new Message( From : new(Email : mailSenderEmail, Name : tenant.Name), To : new() { new(user.Email, user.Login) }, Subject : subject, HtmlPart : htmlPart )); }
public void Action(string aufgabe, string action) { switch (action) { case "Add": _toDosListe.Items.Add(new ToDos { Aufgabe = aufgabe, Erledigt = false }); break; case "Check": var item = _toDosListe.Items.Where(x => x.Aufgabe == aufgabe).FirstOrDefault(); item.Erledigt = !item.Erledigt; break; } var msg = renderer.RenderPartialToStringAsync("_ToDoTableTemplate", _toDosListe); Clients.All.SendAsync("DoneToDo", msg); }
public async Task SendConfirmationEmail(Order order) { try { string content = await razorPartialToString.RenderPartialToStringAsync("_OrderConfirmationEmailPartial", order); Message message = new Message { From = "*****@*****.**", To = new string[] { order.Email }, Subject = $"Order Confirmation #{order.OrderId}", Body = content, IsHtml = true }; await mailService.Send(message); } catch (Exception e) { logger.LogWarning("Can't generate order confirmation e-mail for Order #" + order.OrderId + " because: " + e.Message); } }
public ActionResult DebugEmailTemplate() => Content(partialToStringRenderer.RenderPartialToStringAsync("EmailPage", new EmailPage { Text = "qqqqeeee" }).Result, "text/html");
private async Task <bool> GeneratePageConstructionModel() { LangItem dummyLangItem = new LangItem() { Id = Guid.Empty, LanguageHeaderId = Guid.Parse("11111111-1111-1111-1111-111111111111"), LanguageCodeId = "EN" }; LanguageHeaderModel dummyLanguageHeaderModel = new LanguageHeaderModel() { langHead = new LangHead(), StatusList = StatusList, LanguageCodeSelectList = LanguageCodeSelectList }; dummyLanguageHeaderModel.langHead.LanguageItems.Add(dummyLangItem); var langListHTML = await _renderer.RenderPartialToStringAsync("_LangItemTable", dummyLanguageHeaderModel); langListHTML = langListHTML.Replace("\n", "").Replace("\r", "").Replace("\t", "").ToString(); var langItemListTableHTML = _renderer.GetStringBetween(langListHTML, "<!--LangItemTableRowsStart-->", "<!--LangItemTableRowsEnd-->"); List <string> langItemListRows = langItemListTableHTML.TrimStart().TrimEnd().Replace("<td>", "").Split("</td>").ToList(); for (int i = langItemListRows.Count - 1; i >= 0; i--) { var eol = ","; langItemListRows[i] = langItemListRows[i].TrimStart().TrimEnd(); if (string.IsNullOrWhiteSpace(langItemListRows[i])) { langItemListRows.RemoveAt(i); continue; } if (i == langItemListRows.Count - 1) { eol = ""; } langItemListRows[i] = langItemListRows[i].Replace("langHead_LanguageItems_0__", "langHead_LanguageItems_' + rowCount + '__"); langItemListRows[i] = langItemListRows[i].Replace("langHead.LanguageItems[0]", "langHead.LanguageItems[' + rowCount + ']"); langItemListRows[i] = langItemListRows[i].Replace("11111111-1111-1111-1111-111111111111", "' + headerId + '"); langItemListRows[i] = $"'{langItemListRows[i]}'{eol}"; } langItemRows = langItemListRows.ToArray(); languageHeaderModel = new LanguageHeaderModel() { langHead = this.langHead, StatusList = this.StatusList, LanguageCodeSelectList = this.LanguageCodeSelectList, langQueryList = this.langQueryList }; return(true); }
private async Task <bool> GeneratePageConstructionModel() { ClientHeaderModel dummyClientHeaderModel = new ClientHeaderModel() { clientHead = GenerateDummyClientHeadModel(), StatusList = StatusList, TitleList = TitleList, AddressTypeList = AddressTypeList, langQueryList = this.langQueryList }; var contactCardHTML = await _renderer.RenderPartialToStringAsync("_ClientContact", dummyClientHeaderModel); contactCardHTML = contactCardHTML.Replace("\n", "").Replace("\r", "").Replace("\t", "").ToString(); var addressTableHTML = _renderer.GetStringBetween(contactCardHTML, "<!--AddrTableRowsStart-->", "<!--AddrTableRowsEnd-->"); List <string> addressListRows = addressTableHTML.TrimStart().TrimEnd().Replace("<td>", "").Split("</td>").ToList(); for (int i = addressListRows.Count - 1; i >= 0; i--) { var eol = ","; addressListRows[i] = addressListRows[i].TrimStart().TrimEnd(); if (string.IsNullOrWhiteSpace(addressListRows[i])) { addressListRows.RemoveAt(i); continue; } if (i == addressListRows.Count - 1) { eol = ""; } addressListRows[i] = addressListRows[i].Replace("clientHead_ClientContacts_0__ClientAddresses_0__", "clientHead_ClientContacts_' + contactNumber + '__ClientAddresses_' + rowCount + '__"); addressListRows[i] = addressListRows[i].Replace("clientHead.ClientContacts[0].ClientAddresses[0]", "clientHead.ClientContacts[' + contactNumber + '].ClientAddresses[' + rowCount + ']"); addressListRows[i] = addressListRows[i].Replace("11111111-1111-1111-1111-111111111111", "' + contactId + '"); addressListRows[i] = $"'{addressListRows[i]}'{eol}"; } dummyClientHeaderModel.clientHead.ClientContacts[0].ClientAddresses = new List <ClientAddr>(); contactCardHTML = await _renderer.RenderPartialToStringAsync("_ClientContact", dummyClientHeaderModel); contactCardHTML = contactCardHTML.Replace("\n", "").Replace("\r", "").Replace("\t", "").ToString(); contactCardHTML = contactCardHTML.Replace("collapse0", "collapse' + contactCount + '"); contactCardHTML = contactCardHTML.Replace("heading0", "heading' + contactCount + '"); contactCardHTML = contactCardHTML.Replace("_0__", "_' + contactCount + '__"); contactCardHTML = contactCardHTML.Replace("[0]", "[' + contactCount + ']"); contactCardHTML = contactCardHTML.Replace(".ClientHeaderId\" value=\"00000000-0000-0000-0000-000000000000\"", ".ClientHeaderId\" value=\"' + clientHeaderId + '\""); contactCardHTML = contactCardHTML.Replace("addr_table_00000000-0000-0000-0000-000000000000", "addr_table_' + newContactId + '"); contactCardHTML = contactCardHTML.Replace("<input id=\"AddrTable_Contact_Num_00000000-0000-0000-0000-000000000000\" value=\"0\" hidden />", "<input id=\"AddrTable_Contact_Num_' + newContactId + '\" value=\"' + contactCount + '\" hidden />"); contactCardHTML = contactCardHTML.Replace("AddrTableCount_00000000-0000-0000-0000-000000000000", "AddrTableCount_' + newContactId + '"); contactCardHTML = contactCardHTML.Replace("add_address_00000000-0000-0000-0000-000000000000", "add_address_' + newContactId + '"); clientHeaderModel = new ClientHeaderModel() { clientHead = clientHead, StatusList = StatusList, contactCardHTML = contactCardHTML, addressRows = addressListRows.ToArray(), TitleList = TitleList, AddressTypeList = AddressTypeList, langQueryList = this.langQueryList }; return(true); }