public async Task <ActionResult> Pass(int id) { var msg = await LeaveMessageService.GetByIdAsync(id); msg.Status = Status.Published; bool b = await LeaveMessageService.SaveChangesAsync() > 0; if (b) { var content = new Template(await new FileInfo(Path.Combine(HostEnvironment.WebRootPath, "template", "notify.html")).ShareReadWrite().ReadAllTextAsync(Encoding.UTF8)).Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Set("nickname", msg.NickName).Set("content", msg.Content); using var emails = LeaveMessageService.GetQuery(m => m.GroupTag == msg.GroupTag).Select(m => m.Email).Distinct().ToPooledList().Except(new List <string> { msg.Email, CurrentUser.Email }).ToPooledSet(); var link = Url.Action("Index", "Msg", new { cid = id }, Request.Scheme); foreach (var s in emails) { BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s, ClientIP)); } } return(ResultData(null, b, b ? "审核通过!" : "审核失败!")); }
public async Task <ActionResult> Pass(int id) { var msg = await LeaveMessageService.GetByIdAsync(id); msg.Status = Status.Published; bool b = await LeaveMessageService.SaveChangesAsync() > 0; #if !DEBUG var pid = msg.ParentId == 0 ? msg.Id : LeaveMessageService.GetParentMessageIdByChildId(id); var content = new Template(await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "notify.html"))).Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Set("nickname", msg.NickName).Set("content", msg.Content); var emails = LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(pid).Select(c => c.Email).Except(new List <string> { msg.Email, CurrentUser.Email }).ToHashSet(); var link = Url.Action("Index", "Msg", new { cid = pid }, Request.Scheme); foreach (var s in emails) { BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s)); } #endif return(ResultData(null, b, b ? "审核通过!" : "审核失败!")); }