public async Task<ActionResult> ModifyMentoringReport(MentoringReportViewModel dataRequestViewModel, string deleteFileSns, IEnumerable<HttpPostedFileBase> files) { ViewBag.LeftMenu = Global.MentoringReport; var mentorId = Session[Global.LoginID].ToString(); if (ModelState.IsValid) { var scMentoringReport = await _scMentoringReportService.GetMentoringReportById(dataRequestViewModel.ReportSn); scMentoringReport.Attendee = dataRequestViewModel.Attendee; scMentoringReport.BizWorkSn = dataRequestViewModel.BizWorkSn; scMentoringReport.CompSn = dataRequestViewModel.CompSn; scMentoringReport.MentorAreaCd = dataRequestViewModel.MentorAreaCd; scMentoringReport.MentoringContents = dataRequestViewModel.MentoringContents; scMentoringReport.MentoringDt = dataRequestViewModel.MentoringDt; scMentoringReport.MentoringEdHr = dataRequestViewModel.MentoringEdHr; scMentoringReport.MentoringPlace = dataRequestViewModel.MentoringPlace; scMentoringReport.MentoringStHr = dataRequestViewModel.MentoringStHr; scMentoringReport.MentoringSubject = dataRequestViewModel.MentoringSubject; scMentoringReport.SubmitDt = dataRequestViewModel.SubmitDt; scMentoringReport.UpdId = mentorId; scMentoringReport.UpdDt = DateTime.Now; //삭제파일 상태 업데이트 if (!string.IsNullOrEmpty(deleteFileSns.Trim())) { foreach (var deleteFileSn in deleteFileSns.Split(',').AsEnumerable()) { scMentoringReport.ScMentoringFileInfoes.Select(mtfi => mtfi.ScFileInfo).Where(fi => fi.FileSn == int.Parse(deleteFileSn)).FirstOrDefault().Status = "D"; } } //첨부파일 if (files != null) { var fileHelper = new FileHelper(); foreach (var file in files) { if (file != null) { var savedFileName = fileHelper.GetUploadFileName(file); var subDirectoryPath = Path.Combine(FileType.Mentoring_Report.ToString(), DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString()); var savedFilePath = Path.Combine(subDirectoryPath, savedFileName); var scFileInfo = new ScFileInfo { FileNm = Path.GetFileName(file.FileName), FilePath = savedFilePath, Status = "N", RegId = Session[Global.LoginID].ToString(), RegDt = DateTime.Now }; var scMentoringFileInfo = new ScMentoringFileInfo { ScFileInfo = scFileInfo }; //파일타입에 따라 재정의해서 넣어야 함(첨부파일, 사진) scMentoringFileInfo.Classify = fileHelper.HasImageFile(file) ? "P" : "A"; scMentoringReport.ScMentoringFileInfoes.Add(scMentoringFileInfo); await fileHelper.UploadFile(file, subDirectoryPath, savedFileName); } } } //수정 await _scMentoringReportService.ModifyScMentoringReportAsync(scMentoringReport); return RedirectToAction("MentoringReportList", "MentoringReport"); } ModelState.AddModelError("", "입력값 검증 실패."); return View(dataRequestViewModel); }
public async Task<ActionResult> RegMentoringReport(MentoringReportViewModel dataRequestViewModel, IEnumerable<HttpPostedFileBase> files) { ViewBag.LeftMenu = Global.MentoringReport; var mentorId = Session[Global.LoginID].ToString(); if (ModelState.IsValid) { var scMentoringReport = Mapper.Map<ScMentoringReport>(dataRequestViewModel); scMentoringReport.MentorId = mentorId; scMentoringReport.RegId = mentorId; scMentoringReport.RegDt = DateTime.Now; scMentoringReport.Status = "N"; //첨부파일 if (files != null) { var fileHelper = new FileHelper(); foreach (var file in files) { if (file != null) { var savedFileName = fileHelper.GetUploadFileName(file); var subDirectoryPath = Path.Combine(FileType.Mentoring_Report.ToString(), DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString()); var savedFilePath = Path.Combine(subDirectoryPath, savedFileName); var scFileInfo = new ScFileInfo { FileNm = Path.GetFileName(file.FileName), FilePath = savedFilePath, Status = "N", RegId = Session[Global.LoginID].ToString(), RegDt = DateTime.Now }; var scMentoringFileInfo = new ScMentoringFileInfo { ScFileInfo = scFileInfo }; //파일타입에 따라 재정의해서 넣어야 함(첨부파일, 사진) scMentoringFileInfo.Classify = fileHelper.HasImageFile(file) ? "P" : "A"; scMentoringReport.ScMentoringFileInfoes.Add(scMentoringFileInfo); await fileHelper.UploadFile(file, subDirectoryPath, savedFileName); } } } //저장 int result = await _scMentoringReportService.AddScMentoringReportAsync(scMentoringReport); if (result != -1) return RedirectToAction("MentoringReportList", "MentoringReport"); else { ModelState.AddModelError("", "자료요청 등록 실패."); return View(dataRequestViewModel); } } ModelState.AddModelError("", "입력값 검증 실패."); return View(dataRequestViewModel); }