public ActionResult Edit(int documentISN) { var viewModel = new DocumentViewModel(this.MemberISN, documentISN); return PartialView("_EditDocument", viewModel); }
public ActionResult UploadDocument(DocumentViewModel viewModel) { if (!ModelState.IsValid) { Session["debt_document_isn"] = -1; return RedirectToAction("Index"); } var UserIP = string.Empty; UserIP = Request.ServerVariables["REMOTE_ADDR"]; var document = new DocumentModel(); document.Public = true; document.SignatureStatus = 0; document.MemberISN = this.MemberISN; document.DocName = viewModel.DocName; document.Desc = viewModel.Notes; document.SendIP = UserIP; document.UpdatedBy = -this.MemberISN; if (viewModel.SelectedCreditorID != null) { document.CreditorISN = viewModel.SelectedCreditorID.Value; document.CreditorName = viewModel.GetCreditorName(viewModel.SelectedCreditorID.Value, this.MemberISN); } var addedDate = DateTime.Now; var fullPath = string.Empty; // // get file uploaded if (viewModel.UploadedFile != null && viewModel.UploadedFile.ContentLength > 0) { document.FileName = viewModel.UploadedFile.FileName; document.FileSize = viewModel.UploadedFile.ContentLength; } var documentISN = _docBusiness.UploadDocument(document); // // save file if add document success #region save document isn to session Session["debt_document_isn"] = documentISN; if (documentISN > 0 && !string.IsNullOrEmpty(document.FileName)) { var pathConfig = ConfigurationManager.AppSettings["UploadFolder"]; if (string.IsNullOrEmpty(pathConfig)) { // pathConfig = "C:\\"; pathConfig = Environment.GetLogicalDrives()[0]; // expect C:\\ } // // check path is exist // if not exist, create new folder // document template // yyyyMM\\Documents\\dd\\123 var docPath = _docBusiness.GetDocumentPath(documentISN, addedDate); fullPath = Path.Combine(pathConfig, docPath); if (!Directory.Exists(fullPath)) { try { Directory.CreateDirectory(fullPath); fullPath = Path.Combine(fullPath.TrimEnd('/', '\\'), document.FileName); // // save file if create folder success try { viewModel.UploadedFile.SaveAs(fullPath); } catch (Exception ex) { _logger.Error(ex, "Cannot save image to {0}", fullPath); } } catch (Exception ex) { _logger.Error(ex, "Cannot create directory"); } } } #endregion return RedirectToAction("Index"); }
public ActionResult Upload() { var viewModel = new DocumentViewModel(this.MemberISN); return PartialView("_UploadDocument", viewModel); }
public ActionResult Edit(DocumentViewModel viewModel) { if (!ModelState.IsValid) { Session["debt_document_isn"] = -1; return RedirectToAction("Index"); } var document = new DocumentModel(); document.Public = true; document.ID = viewModel.DocumentISN; document.MemberISN = this.MemberISN; document.Desc = viewModel.Notes; document.DocName = viewModel.DocName; if (viewModel.SelectedCreditorID != null) { document.CreditorISN = viewModel.SelectedCreditorID.Value; document.CreditorName = viewModel.GetCreditorName(viewModel.SelectedCreditorID.Value, this.MemberISN); } document.AddedDate = viewModel.AddedDate; // // TODO // save file var fullPath = string.Empty; var canSave = false; // // save file #region save file if (viewModel.UploadedFile != null && viewModel.UploadedFile.ContentLength > 0) { document.FileName = viewModel.UploadedFile.FileName; document.FileSize = viewModel.UploadedFile.ContentLength; var pathConfig = ConfigurationManager.AppSettings["UploadFolder"]; if (string.IsNullOrEmpty(pathConfig)) { pathConfig = Environment.GetLogicalDrives()[0]; // expect C:\\ } // // check path is exist // if not exist, create new folder // var path = Server.MapPath("~/" + pathConfig); // var docPath = _docBusiness.GetDocumentPath(viewModel.DocumentISN, document.AddedDate); var docPath = _premierBusiness.GetDocumentPath(viewModel.DocumentISN, document.AddedDate); fullPath = Path.Combine(pathConfig, docPath); if (!Directory.Exists(fullPath)) { try { Directory.CreateDirectory(fullPath); canSave = true; } catch (Exception ex) { canSave = false; _logger.Error(ex.Message, "Cannot create directory {0}.", fullPath); } } fullPath = Path.Combine(fullPath.TrimEnd('/', '\\'), document.FileName); canSave = true; } #endregion var success = _premierBusiness.EditDocument(document); Session["debt_document_edit"] = true; if (success > 0) { Session["debt_document_isn"] = document.ID; if (canSave) { try { viewModel.UploadedFile.SaveAs(fullPath); } catch (Exception ex) { _logger.Error(ex, "Cannot save file"); } } } else { Session["debt_document_isn"] = -1; } return RedirectToAction("Index"); }