今天功課根據審核人產生相對應的Email
完成後Controller如下
[HttpPost]
publicActionResult Create(CheckForm checkform)
{
if (ModelState.IsValid)
{
db.CheckForm.Add(newCheckForm(){
Applicants = checkform.Applicants,
ApplyDate = DateTime.Now,
ApplyContent = checkform.ApplyContent,
Project = checkform.Project,
ReviewerID = checkform.ReviewerID});
db.SaveChanges();
//Send mail with URL by yuan
SmtpClient sc = newSmtpClient("localhost");
//為了取得上方存入資料的ID,新增一個條件撈出,取名為checkform2,指定p.Applicants撈出上方checkform的Applicants並列出清單,OrderByDecsending根據日期降冪排列,FirstOrDefault取出第一筆
CheckForm checkform2 = db.CheckForm.Where(p => p.Applicants == checkform.Applicants).OrderByDescending(p=>p.ApplyDate).FirstOrDefault();
string verify_url = newUri(
Request.Url,
RouteTable.Routes.GetVirtualPath(
Request.RequestContext,
newRouteValueDictionary(
new { controller = "Home", action = "Detail", id = checkform2.ID}
)
).VirtualPath
).AbsoluteUri;
ViewBag.url = verify_url;
//取得Reviewer.Email by Jaye&Joe
Reviewer reviewermail = db.Reviewer.Where(p => p.ID ==checkform.ReviewerID).FirstOrDefault();
ViewBag.email = reviewermail.Email;