public ActionResult ResponseComment(int courseMonitoringReportId, String dltComment) { CRMContext db = new CRMContext(); var report = db.CourseMonitoringReports.SingleOrDefault(c => c.CourseMonitoringReportId == courseMonitoringReportId); if (report != null) { report.dltComment = dltComment; db.Entry(report).State = EntityState.Modified; db.SaveChanges(); var clEmail = report.AnnualCourse.Account.Profile.email; var userName = User.Identity.Name; var user = db.Accounts.SingleOrDefault(u => u.userName == userName); var body = "<p>Email From: {0} ({1})</p><p>Message: {2}</p><p>Content: {3}</p><p>Link: {4}</p>"; var uri = HttpContext.Request.Url; String url = uri.GetLeftPart(UriPartial.Authority); url = url + "/CL/ReportDetail?id=" + report.CourseMonitoringReportId; var message = string.Format(body, user.Profile.name, user.Profile.email, "Your report has been repsoned.",dltComment,url); Task.Run(async () => await CustomHtmlHelpers.Helpers.sendMail(clEmail, message)); } return RedirectToAction("Detail", new { reportId = courseMonitoringReportId }); }
public ActionResult SubmitComment(int courseMonitoringReportId, String comment_content) { System.Diagnostics.Debug.WriteLine("SubmitComment " + comment_content); if (ModelState.IsValid) { CRMContext db = new CRMContext(); Comment cmt = new Comment(); cmt.content = comment_content; var acc = db.Accounts.SingleOrDefault(a => a.userName == User.Identity.Name); cmt.accountId = acc.accountId; cmt.time = DateTime.Now; cmt.monitoringReportId = courseMonitoringReportId; db.Comments.Add(cmt); db.SaveChanges(); return RedirectToAction("Detail", new { reportId = courseMonitoringReportId }); } return View(); }
public ActionResult CreateReport(CourseMonitoringReport acr, String waiting) { if (ModelState.IsValid) { CRMContext db = new CRMContext(); if (waiting != null) { acr.approveStatusId = 2; var userName = User.Identity.Name; var user = db.Accounts.SingleOrDefault(u => u.userName == userName); var AnnualCourse = db.AnnualCourses.SingleOrDefault(a => a.annualCourseId == acr.annualCourseId); int CMId = (int)AnnualCourse.Course.Faculty.cmAccount; var Cm = db.Accounts.SingleOrDefault(u => u.accountId == CMId); db.CourseMonitoringReports.Add(acr); db.SaveChanges(); int ID = db.CourseMonitoringReports.Max(item => item.CourseMonitoringReportId); var body = "<p>Email From: {0} ({1})</p><p>Message: {2}</p><p>Link: {3}</p>"; var uri = HttpContext.Request.Url; String url = uri.GetLeftPart(UriPartial.Authority); url = url + "/CM/Detail?reportId=" +ID; var message = string.Format(body, user.Profile.name, user.Profile.email, "There is a report that you need to approve", url); Task.Run(async () => await CustomHtmlHelpers.Helpers.sendMail(Cm.Profile.email, message)); }else{ db.CourseMonitoringReports.Add(acr); db.SaveChanges(); } return RedirectToAction("ReportList"); } return View(); }
public ActionResult TakeAnnualCourse(int annualCourseId) { CRMContext db = new CRMContext(); AnnualCourse anCourse = db.AnnualCourses.SingleOrDefault(ac => ac.annualCourseId == annualCourseId); var currUser = User.Identity; String userName = currUser.Name; Account a = db.Accounts.SingleOrDefault(u => u.userName == userName); anCourse.clAccount = a.accountId; anCourse.Status = "Activate"; db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult DeleteReport(int id) { CRMContext db = new CRMContext(); CourseMonitoringReport acr = db.CourseMonitoringReports.SingleOrDefault(a => a.CourseMonitoringReportId == id); if (acr == null) { return HttpNotFound(); } db.CourseMonitoringReports.Remove(acr); db.SaveChanges(); return RedirectToAction("ReportList"); }
public async Task<ActionResult> EditReport(CourseMonitoringReport acr, String waiting) { CRMContext db = new CRMContext(); if (ModelState.IsValid) { if (waiting != null) { acr.approveStatusId=2; var userName = User.Identity.Name; var user = db.Accounts.SingleOrDefault(u => u.userName == userName); var AnnualCourse = db.AnnualCourses.SingleOrDefault(a => a.annualCourseId == acr.annualCourseId); int CMId =(int) AnnualCourse.Course.Faculty.cmAccount; var Cm = db.Accounts.SingleOrDefault(u => u.accountId == CMId); var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p><p>Link: {3}</p>"; var uri = HttpContext.Request.Url; String url = uri.GetLeftPart(UriPartial.Authority); url = url + "/CM/Detail?reportId=" + acr.CourseMonitoringReportId; var message = new MailMessage(); message.To.Add(new MailAddress(Cm.Profile.email)); message.Subject = "Course Monitoring Report"; message.Body = string.Format(body, user.Profile.name, user.Profile.email, "There is a report That you need to approve", url); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { await smtp.SendMailAsync(message); } } db.Entry(acr).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("ReportList"); } return View(acr); }
public ActionResult Approve(int courseMonitoringReportId, int status, String approve_desc) { CRMContext db = new CRMContext(); var report = db.CourseMonitoringReports.SingleOrDefault(c => c.CourseMonitoringReportId == courseMonitoringReportId); if (report != null) { var statusName = ""; report.approveStatusId = status; report.approve_desc = approve_desc; db.Entry(report).State = EntityState.Modified; db.SaveChanges(); var userName = User.Identity.Name; var user = db.Accounts.SingleOrDefault(u => u.userName == userName); var ClEmail = report.AnnualCourse.Account.Profile.email; var pvcEmail = report.AnnualCourse.Course.Faculty.Account2.Profile.email; var dltEmail = report.AnnualCourse.Course.Faculty.Account1.Profile.email; if (status == 3) { statusName = "rejected"; } else if (status == 4) { statusName = "approved"; } var uri = HttpContext.Request.Url; String url = uri.GetLeftPart(UriPartial.Authority); String clURL = url + "/CL/ReportDetail?id=" + report.CourseMonitoringReportId; var body = "<p>Email From: {0} ({1})</p><p>Message: {2}</p><p>Link: {3}</p>"; var message = string.Format(body, user.Profile.name, user.Profile.email, "Your report have been " + statusName + " by " + user.Profile.name, clURL); Task.Run(async () => await CustomHtmlHelpers.Helpers.sendMail(ClEmail, message)); String dltURL = url + "/DLT/Detail?reportId=" + report.CourseMonitoringReportId; var dtlbody = "<p>Email From: {0} ({1})</p><p>Message: {2}</p><p>Link: {3}</p>"; var dltmessage = string.Format(dtlbody, user.Profile.name, user.Profile.email, "There is a report of " + report.AnnualCourse.Account.Profile.name, dltURL); Task.Run(async () => await CustomHtmlHelpers.Helpers.sendMail(dltEmail, dltmessage)); String pvcURL = url + "/PVC/Detail?reportId=" + report.CourseMonitoringReportId; var pvcbody = "<p>Email From: {0} ({1})</p><p>Message: {2}</p><p>Link: {3}</p>"; var pvcmessage = string.Format(pvcbody, report.AnnualCourse.Account.Profile.name, report.AnnualCourse.Account.Profile.email, "There is a report of " + report.AnnualCourse.Account.Profile.name, pvcURL); Task.Run(async () => await CustomHtmlHelpers.Helpers.sendMail(pvcEmail, pvcmessage)); } return RedirectToAction("Detail", new { reportId = courseMonitoringReportId }); }