public ActionResult PPKComment(int id) { ViewData["ReportId"] = id; PPKCommentViewModel comment = new PPKCommentViewModel(); var report = _reportLogic.GetById(id); comment.PPKComment = report.PPKComment; return(View(comment)); }
public ActionResult PPKComment(HttpPostedFileBase file, PPKCommentViewModel model) { if (file == null) { ViewData["ReportId"] = model.ReportId; ModelState.AddModelError(string.Empty, "Mohon upload file pendukung."); return(View(model)); } var oldReport = _reportLogic.GetById(model.ReportId); var comment = !string.IsNullOrEmpty(oldReport.PPKComment) ? oldReport.PPKComment + "<br />" + model.Comment : model.Comment; Report report = new Report() { PPKComment = comment, Id = model.ReportId }; _reportLogic.UpdatePPKComment(report); if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var filePath = model.ReportId + "_" + fileName; var path = Path.Combine(Server.MapPath("~/Content/UploadPPK"), filePath); file.SaveAs(path); PPKFile ppkFile = new PPKFile(); ppkFile.FileName = fileName; ppkFile.ReportId = model.ReportId; _ppkFileLogic.Create(ppkFile); } try { var msg = new MailMessage(); msg.To.Add(new MailAddress(ConfigurationManager.AppSettings["AdminEmail"])); msg.Subject = "LAPOR-BRANTAS New Comment From PPK"; msg.Body = model.Comment; msg.From = new MailAddress("*****@*****.**"); using (var client = new SmtpClient() { Host = "relay-hosting.secureserver.net", Port = 25, EnableSsl = false, UseDefaultCredentials = false }) { client.Send(msg); } } catch (Exception ex) { } return(RedirectToAction("Assigned")); }