public ActionResult Manage() { MonthlyReportManageModels model = new MonthlyReportManageModels { Date = DateTime.UtcNow.ConvertToDateYearMonthString(User.Identity.GetUserTimeZone()), }; return(View(model)); }
public ActionResult New(MonthlyReportManageModels model, HttpPostedFileBase PDFFile) { if (PDFFile == null) { ModelState.AddModelError("", "Upload file cannot be empty."); } if (ModelState.IsValid) { if (PDFFile.IsPDF()) { try { //PDF Format : [MM-yyyy_pdfname.pdf] string targetFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["PDF_MonthlyReportPath"]); string fileName = model.Date.Replace("/", "") + ".pdf"; string targetPath = Path.Combine(targetFolder, fileName); PDFFile.SaveAs(targetPath); Success("Successfully uploaded report " + PDFFile.FileName + ". (Renamed to " + fileName + ")"); } catch (Exception ex) { Log.Error(ex.Message, ex); Warning("Something went wrong when server trying to upload this file, if problem still persist please contact administrator."); } } else { Warning("Upload File is not a valid PDF file. Please choose a valid PDF file to upload."); } } else { Warning("Please make sure input field is correctly filled in."); } return(RedirectToAction("Manage")); }