public async Task <IActionResult> ContactFoundFinder(string date, int?id, string name, string mail) { if (date == null || id == null || name == null) { return(NotFound()); } char[] array = date.ToCharArray(); Array.Reverse(array); var newdate = new string(array); // date = date.Reverse().ToString(); var link = Url.Action("SelectMeetingDate", "Meeting", new { area = "User", Num = id, dat = newdate }, Request.Scheme); System.IO.File.WriteAllText("Meetinglink.txt", link); var claim = await foundItemClaim.GetFoundItemClaimById(id); claim.IsAdminValid = true; foundItemClaim.Save(); var message = new Dictionary <string, string> { { "FName", $"{name}" }, { "EmailClaimLink", link } }; await emailSender.SendEmailAsync(mail, "Meeting Arrangement", message, "SetUpMeeting"); return(RedirectToAction("ValidatedFoundItemsClaim", "ClaimManagement", new { area = "Admin" })); }
public async Task <bool> SendConfirmationEmail(string confirmEmail, string userId, string confirmCode) { _logger.LogInformation("Sending confirmation email"); if (string.IsNullOrWhiteSpace(confirmEmail)) { _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(confirmEmail)); return(false); } if (string.IsNullOrWhiteSpace(userId)) { _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(userId)); return(false); } if (string.IsNullOrWhiteSpace(confirmCode)) { _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(confirmCode)); return(false); } try { // Confirm code needs to be url encoded for verification to work var encodedConfirmCode = UrlEncoder.Default.Encode(confirmCode); var model = new ConfirmationEmailModel() { BaseUrl = _url, Title = "CoreWiki Email Confirmation", ReturnUrl = $"{_url}Identity/Account/ConfirmEmail?userId={userId}&code={encodedConfirmCode}", ConfirmEmail = confirmEmail }; var messageBody = await _emailMessageFormatter.FormatEmailMessage( TemplateProvider.ConfirmationEmailTemplate, model); return(await _emailNotifier.SendEmailAsync( confirmEmail, "Please confirm your email address", messageBody)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); #if DEBUG throw; #else return(false); #endif } }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(model.UserName.ToUpper()); if (user == null) { user = new ApplicationUser { UserName = model.UserName, Email = model.UserName, FirstName = model.FirstName, LastName = model.LastName }; var result = await userManager.CreateAsync(user, model.Password); //user = await userManager.FindByEmailAsync(model.UserName); if (!result.Succeeded) { foreach (var Error in result.Errors) { ModelState.AddModelError("Password", Error.Description); } return(View(model)); } await userManager.AddToRoleAsync(user, "User"); await userManager.AddClaimAsync(user, new Claim("firstname", model.FirstName)); var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var ConfirmEmail = Url.Action("ConfirmEmailAddress", "Account", new { token = token, email = user.Email }, Request.Scheme); var message = new Dictionary <string, string> { { "FName", $"{model.FirstName}" }, { "EmailLink", $"{ConfirmEmail}" } }; var resul = await emailNotifier.SendEmailAsync(model.UserName, "Email Confirmation", message, "EmailConfirmation"); System.IO.File.WriteAllText("Emailtoken.txt", ConfirmEmail); var msg = "Swal.fire({position: 'top-end',icon: 'success',title: 'Registration Complete, Check your Email for Confirmation', showConfirmButton: false, timer: 3500})"; TempData["message"] = $"<script type='text/javascript'> {msg} </script>"; ViewBag.Trial = $"<script type='text/javascript'> {msg} </script>"; // TempData["message"] = "Registration Complete, Check your Email for Confirmation"; return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Account already Exist"); } return(View(model)); }
private async Task HandleAsync(DayHasPassed dhp) { DateTime today = DateTime.Now; IEnumerable <MaintenanceJob> jobsToNotify = await _repo.GetMaintenanceJobsForTodayAsync(today); foreach (var jobsPerCustomer in jobsToNotify.GroupBy(job => job.CustomerId)) { // build notification body string customerId = jobsPerCustomer.Key; Customer customer = await _repo.GetCustomerAsync(customerId); StringBuilder body = new StringBuilder(); body.AppendLine($"Dear {customer.Name},\n"); body.AppendLine($"We would like to remind you that you have an appointment with us for maintenance on your vehicle(s):\n"); foreach (MaintenanceJob job in jobsPerCustomer) { body.AppendLine($"- {job.StartTime.ToString("dd-MM-yyyy")} at {job.StartTime.ToString("HH:mm")} : " + $"{job.Description} on vehicle with license-number {job.LicenseNumber}"); } body.AppendLine($"\nPlease make sure you're present at least 10 minutes before the (first) job is planned."); body.AppendLine($"Once arrived, you can notify your arrival at our front-desk.\n"); body.AppendLine($"Greetings,\n"); body.AppendLine($"The PitStop crew"); // send notification await _emailNotifier.SendEmailAsync( customer.EmailAddress, "*****@*****.**", "Vehicle maintenance reminder", body.ToString()); // remove jobs for which a notification was sent await _repo.RemoveMaintenanceJobsAsync(jobsPerCustomer.Select(job => job.JobId)); } }
public async Task <IActionResult> SelectMeetingDate(int?id, string user, MeetingDateViewModel meetingDate) { if (id == null || user == null) { return(NotFound()); } if (ModelState.IsValid) { var claim = await claimRepository.GetFoundItemClaimById(id); if (user != claim.ApplicationUserId) { return(View()); } var meeting = new Meeting { FoundItem = claim.FoundItem, UserSelectedDate = (DateTime)meetingDate.FirstDate, USerSelectedDate2 = (DateTime)meetingDate.SecondDate, LocalGovernmentId = meetingDate.LGAId }; meetingRepository.Create(meeting); meetingRepository.Save(); var firstdate = ((DateTime)meetingDate.FirstDate).ToShortDateString(); var seconddate = ((DateTime)meetingDate.SecondDate).ToShortDateString(); var link = Url.Action("ConfirmDate", "Meeting", new { area = "User", id = claim.Id, firstDate = firstdate, secondDate = seconddate }, Request.Scheme); await System.IO.File.WriteAllTextAsync("ConfirmDate.txt", link); var message = new Dictionary <string, string> { { "FName", " User" }, { "EmailClaimLink", link } }; await emailNotifier.SendEmailAsync(claim.ApplicationUser.Email, "Meeting Arrangement", message, "SetUpMeeting"); return(RedirectToAction("Success", "Account")); } return(RedirectToAction("SelectMeetingDate")); }
private async Task HandleAsync(CustomerRegisteredEvent customerRegisteredEvent) { StringBuilder mailBody = new StringBuilder(); mailBody.AppendLine($"Dear {customerRegisteredEvent.FirstName},"); mailBody.AppendLine($"Welcome! Your email address: {customerRegisteredEvent.EmailAddress} is registered with us."); await _emailNotifier.SendEmailAsync(customerRegisteredEvent.EmailAddress, "*****@*****.**", "Welcome!", mailBody.ToString()); }
/// <inheritdoc /> public async Task HandleAsync(NotificationMessage <EmailNotificationMessage> notificationMessage) { logger.LogInformation("Start handle message for sending email."); notificationMessage.ThrowIfNull(nameof(notificationMessage)); var email = await emailMessageFactory.CreateFromNotificationMessage(notificationMessage); await emailNotifier.SendEmailAsync(email); }
public Task StartAsync(CancellationToken cancellationToken) { // Console.log("startAsync"); using (var scope = scopeFactory.CreateScope()) { var factory = new ConnectionFactory() { HostName = "localhost", UserName = "******", Password = "******" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "Notification", durable: true, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var eabody = ea.Body; var message = Encoding.UTF8.GetString(eabody); Console.WriteLine(message); Notification notification = JsonSerializer.DeserializeFromString <Notification>(message); Console.WriteLine("Sent notification to: {0}", notification.EmailAddress); // // build notification body StringBuilder body = new StringBuilder(); body.AppendLine($"Dear User,\n"); body.AppendLine($"There has beed a change in Rank of {notification.FollowerId}:\n"); body.AppendLine($"Old Rank: {notification.OldRank} \nNew Rank: {notification.NewRank} "); // send notification _emailNotifier.SendEmailAsync( notification.EmailAddress, "*****@*****.**", "Rank Changed for " + notification.FollowerId, body.ToString()); }; channel.BasicConsume(queue: "Notification", autoAck: true, consumer: consumer); // Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } } // _timer = new Timer(DoWork, null, TimeSpan.Zero, // TimeSpan.FromSeconds(5)); return(Task.CompletedTask); }
private async Task HandleAsync(AnswerSubmitted cr) { Answer answer = new Answer { AnswerId = cr.AnswerId, QuestionId = cr.QuestionId, CustomerId = cr.CustomerId, AnswerString = cr.AnswerString }; Question question = await _repo.GetQuestionAsync(answer.QuestionId); Customer customer = await _repo.GetCustomerAsync(answer.CustomerId); Log.Information("Register answer: {AnswerId}, {QuestionId}, {CustomerId}, {AnswerString}", answer.AnswerId, answer.QuestionId, answer.CustomerId, answer.AnswerString); StringBuilder body = new StringBuilder(); body.AppendLine($"Dear {customer.Name},\n"); body.AppendLine($"The following question has been answered:\n"); body.AppendLine($"{question.QuestionString}"); body.AppendLine($"\nThe answer from our customer service is as followed:\n"); body.AppendLine($"{answer.AnswerString}"); body.AppendLine($"\nIf you have futher questions please contact our customer service.\n"); body.AppendLine($"Greetings,\n"); body.AppendLine($"The Ball crew"); Log.Information("Sent notification to: {CustomerName}", customer.Name); // send notification await _emailNotifier.SendEmailAsync( customer.EmailAddress, "*****@*****.**", "Your Question has been answered", body.ToString()); await _repo.RegisterAnswerAsync(answer); }
private async Task HandleAsync(UserRegistered userRegistered) { User user = new User { Id = userRegistered.Id, FirstName = userRegistered.FirstName, LastName = userRegistered.LastName, PhoneNumber = userRegistered.PhoneNumber, EmailAddress = userRegistered.EmailAddress }; await repository.RegisterUserAsync(user); // Send Notification StringBuilder body = new StringBuilder(); body.AppendLine($"Dear {userRegistered.FirstName},\n"); body.AppendLine($"Put some nice welcome message here...\n"); await emailNotifier.SendEmailAsync( userRegistered.EmailAddress, "*****@*****.**", $"Welcome, {userRegistered.FirstName}", body.ToString()); }
public async Task <bool> NotifyAuthorNewComment(CoreOdinUser author, Article article, Comment comment) { if (!author.CanNotify) { return(false); } if (string.IsNullOrWhiteSpace(author.Email)) { return(false); } var model = new { AuthorName = author.UserName, Title = "Odin Notification", CommentDisplayName = comment.DisplayName, ArticleTitle = article.Topic, ArticleUrl = GetUrlForArticle(article) }; var messageBody = await _emailMessageFormatter.FormatEmailMessage("NewComment", model); return(await _emailNotifier.SendEmailAsync(author.Email, "Someone said something about your article", messageBody)); }
public async Task <IActionResult> Create(LostItemClaimViewModel model) { var user = await userManager.GetUserAsync(HttpContext.User); var lostItem = await lostItemRepository.GetLostItemById(model.LostItemId); if (user == null || user == lostItem.LostItemUser) { ModelState.AddModelError("", "You Cant Claim an Item you Logged"); return(View()); } if (ModelState.IsValid) { //Check if user has claimed Item before foreach (var clam in lostItem.LostItemClaims) { if (user.Id == clam.ApplicationUserId) { ModelState.AddModelError("", "You Cant claim an Item twice"); return(View()); } } Image image = null; if (model.Image != null) { if (!utility.IsSizeAllowed(model.Image)) { ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB"); return(View(model)); } if (!utility.IsImageExtensionAllowed(model.Image)) { ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp are allowed"); return(View(model)); } var photopath = utility.SaveImageToFolder(model.Image); image = new Image { ImagePath = photopath }; } user.PhoneNumber = model.PhoneNumber; user.PhoneNumber = user.PhoneNumber ?? model.PhoneNumber; LostItemClaim claim = new LostItemClaim { ApplicationUser = user, LostItemId = model.LostItemId, Description = model.Description, DateFound = model.DateFound, WhereItemWasFound = model.WhereItemWasFound, Image = image }; claimRepository.Create(claim); // System.IO.File.WriteAllText("resetlink.txt", ConfirmEmail); //send mail var ConfirmClaim = Url.Action("Claims", "LostItem", new { area = "User", id = lostItem.Id }, Request.Scheme); var message = new Dictionary <string, string> { { "UName", $"{lostItem.LostItemUser.FirstName}" }, { "FName", $"{user.FirstName}" }, { "ClaimLink", $"{ConfirmClaim}" } }; await emailNotifier.SendEmailAsync(lostItem.LostItemUser.Email, "New Claim", message, "LostItemClaim"); claimRepository.Save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(FoundItemClaimViewModel model) { var user = await userManager.GetUserAsync(HttpContext.User); var foundItem = await foundItemRepository.GetFoundItemById(model.FoundItemId); if (user == null || user == foundItem.FoundItemUser) { ModelState.AddModelError("", "You Cant Claim an Item you Logged"); return(View()); } if (ModelState.IsValid) { foreach (var clam in foundItem.FoundItemClaims) { if (user == clam.ApplicationUser) { ModelState.AddModelError("", "You Cant claim an Item twice"); return(View()); } } Image image = null; if (model.Image != null) { if (!utility.IsSizeAllowed(model.Image)) { ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB"); return(View(model)); } if (!utility.IsImageExtensionAllowed(model.Image)) { ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp are allowed"); return(View(model)); } var photoPath = utility.SaveImageToFolder(model.Image); image = new Image { ImagePath = photoPath }; } user.PhoneNumber = user.PhoneNumber ?? model.PhoneNumber; var claim = new FoundItemClaim { ApplicationUser = user, FoundItemId = model.FoundItemId, Description = model.Description, DateLost = model.DateLost, WhereItemWasLost = model.WhereItemWasLost, Image = image, }; claimRepository.Create(claim); claimRepository.Save(); var ConfirmEmail = Url.Action("Claims", "FoundItem", new { area = User, id = foundItem.Id }, Request.Scheme); var message = new Dictionary <string, string> { { "UName", $"{foundItem.FoundItemUser.FirstName}" }, { "FName", $"{user.FirstName}" }, { "ClaimLink", $"{ConfirmEmail}" } }; await emailNotifier.SendEmailAsync(foundItem.FoundItemUser.Email, "New Claim", message, "foundItemClaim"); return(RedirectToAction(nameof(Index))); } return(View(model)); }