async Task sendMail_GoalAchieve() { var templateName = "Goal Achieved"; var emailTemplate = DbContext.EmailTemplates.Where(et => et.TemplateName == templateName).FirstOrDefault(); if (emailTemplate == null) { return; } foreach (var user in DbContext.Users) { if (!user.Email.StartsWith("raychangrhj") && !user.Email.StartsWith("chung.le.rhj")) { continue; } //============================================================================================ UserSummaryInfoModel userInfo = new UserSummaryInfoModel(DbContext, user); if (userInfo.CurrentDegrees < 180) { continue; } var body = userInfo.getAdjustedTemplate(emailTemplate.TemplateContent); await EmailService.SendAsync(user.Email, "EasyFlexibility Goal Achieve", body, body).ConfigureAwait(false); } }
async Task sendMail_SpecialOffers() { var templateName = "Special Offers"; var emailTemplates = DbContext.EmailTemplates.Where(et => et.TemplateName == templateName).ToList(); foreach (var emailTemplate in emailTemplates) { if (DateTime.Now.ToString("mm/dd/yy") != emailTemplate.SendCondition) { return; } foreach (var user in DbContext.Users) { if (!user.Email.StartsWith("raychangrhj") && !user.Email.StartsWith("chung.le.rhj")) { continue; } //============================================================================================ UserSummaryInfoModel userInfo = new UserSummaryInfoModel(DbContext, user); var body = userInfo.getAdjustedTemplate(emailTemplate.TemplateContent); await EmailService.SendAsync(user.Email, "EasyFlexibility Special Offer", body, body).ConfigureAwait(false); } } }
public async Task <ActionResult> ConfirmEmail(string userId, string code) { try { if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(code) && !await UserManager.IsEmailConfirmedAsync(userId)) { var result = await UserManager.ConfirmEmailAsync(userId, code); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(userId); await SignInManager.SignInAsync(user, false, false); var anonymAngleMeasurement = await DbContext.AnonymAngleMeasurements.SingleOrDefaultAsync(m => m.Email.Equals(user.Email, StringComparison.OrdinalIgnoreCase)); if (anonymAngleMeasurement != null) { var angleMeasurement = DbContext.AngleMeasurements.Create(); DbContext.AngleMeasurements.Add(angleMeasurement); angleMeasurement.Id = anonymAngleMeasurement.Id; angleMeasurement.Angle = anonymAngleMeasurement.Angle; angleMeasurement.DateTimeStamp = anonymAngleMeasurement.DateTimeStamp; angleMeasurement.UserId = userId; angleMeasurement.AngleMeasurementCategoryId = anonymAngleMeasurement.AngleMeasurementCategoryId; DbContext.AnonymAngleMeasurements.Remove(anonymAngleMeasurement); try { await DbContext.SaveChangesAsync(); var body = Engine.Razor.RunCompile("AnonymMeasurementMessage", typeof(string), $"{AppSettings.StorageBaseUrl}{AppSettings.StoragePhotoContainerName}/{angleMeasurement.Id}.{AppSettings.StorageBlobExtension}"); var templateName = "Welcome"; var emailTemplate = DbContext.EmailTemplates.Where(et => et.TemplateName == templateName).FirstOrDefault(); if (emailTemplate != null) { UserSummaryInfoModel userInfo = new UserSummaryInfoModel(DbContext, user); body = userInfo.getAdjustedTemplate(emailTemplate.TemplateContent); } await UserManager.SendEmailAsync(user.Id, "Your first measurement", body); } catch { } } return(View("ConfirmEmail")); } } } catch (Exception) { return(View("Error")); } return(View("Error")); }
async Task sendMail_TrainingCheck() { var templateName = "Training Check"; var emailTemplate = DbContext.EmailTemplates.Where(et => et.TemplateName == templateName).FirstOrDefault(); if (emailTemplate == null) { return; } var sendConditionItems = emailTemplate.SendCondition.Split('#'); int periodicDays = 7; if (sendConditionItems[0] == "true") { periodicDays = int.Parse(sendConditionItems[1]); } if (DateTime.Now.Day % periodicDays > 0) { return; } int minProgress = 0; if (sendConditionItems[2] == "true") { minProgress = int.Parse(sendConditionItems[3]); } foreach (var user in DbContext.Users) { if (!user.Email.StartsWith("raychangrhj") && !user.Email.StartsWith("chung.le.rhj")) { continue; } //============================================================================================ UserSummaryInfoModel userInfo = new UserSummaryInfoModel(DbContext, user); if (userInfo.ProgressRate >= minProgress) { continue; } var body = userInfo.getAdjustedTemplate(emailTemplate.TemplateContent); await EmailService.SendAsync(user.Email, "EasyFlexibility Training Check", body, body).ConfigureAwait(false); } }