public DocumentForTaskViewModel(DocumentAdditionalInfo info) { _id = info._id; FilePath = info.FilePath; InfoName = info.InfoName; InfoValue = info.InfoValue; }
public ActionResult SaveNotes(string noteId) { var note = RepositoryContext.Current.GetOne <ProjectNotes>(p => p._id == noteId); var project = RepositoryContext.Current.GetOne <Project>(pr => pr._id == note.ProjectId); var result = new List <AdditionalInfo>(); if (note.NoteDocument != null) { result = note.NoteDocument.ToList(); } else { note.NoteDocument = result; } var statuses = new List <ViewDataUploadFilesResult>(); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; string fileName = Path.GetFileName(file.FileName); string physicalPath = Path.Combine( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project._id)), fileName); if (!Directory.Exists( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project._id)))) { Directory.CreateDirectory( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project._id))); } file.SaveAs(physicalPath); var document = new DocumentAdditionalInfo(); document.FilePath = physicalPath; document.InfoName = fileName; document._id = ObjectId.GenerateNewId().ToString(); result.Add(document); statuses.Add(new ViewDataUploadFilesResult { name = fileName, size = file.ContentLength, type = file.ContentType, url = "/AdditionalInfo/DownloadNotesInfo?projectId=" + noteId + "&docId=" + document._id, thumbnail_url = @"data:image/png;base64," + EncodeFile(physicalPath), delete_type = "GET", }); } note.NoteDocument = result; RepositoryContext.Current.Update(note); return(Json(statuses)); }
public ActionResult Save(string id, IEnumerable <HttpPostedFileBase> attachments) { var note = RepositoryContext.Current.GetOne <ProjectNotes>(p => p._id == id); var project = RepositoryContext.Current.GetOne <Project>(pr => pr._id == note.ProjectId); var result = new List <AdditionalInfo>(); if (note.NoteDocument != null) { result = note.NoteDocument.ToList(); } else { note.NoteDocument = result; } foreach (var file in attachments) { string fileName = Path.GetFileName(file.FileName); string physicalPath = Path.Combine( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project.Name)), fileName); if (!Directory.Exists( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project.Name)))) { Directory.CreateDirectory( Server.MapPath(string.Format("~/App_Data/ProjectAppendix/{0}/", project.Name))); } file.SaveAs(physicalPath); var document = new DocumentAdditionalInfo(); document.FilePath = physicalPath; document.InfoName = fileName; document._id = ObjectId.GenerateNewId().ToString(); result.Add(document); } note.NoteDocument = result; RepositoryContext.Current.Update(note); return(Content("")); }
public ActionResult SaveMessage(string messageId) { var statuses = new List <ViewDataUploadFilesResult>(); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; string fileName = Path.GetFileName(file.FileName); string physicalPath = AdditionalInfoManager.GetPhysicalPath( "messageAppendix/{1}/{0}/", new[] { User.Identity.Name, DateTime.Now.ToString("MM-dd-yy") }); file.SaveAs(physicalPath + fileName); var document = new DocumentAdditionalInfo { FilePath = physicalPath + fileName, InfoName = fileName, _id = ObjectId.GenerateNewId().ToString() }; _portalMessage.AddAppendix( User.Identity.Name, messageId, document); statuses.Add(new ViewDataUploadFilesResult { name = fileName, size = file.ContentLength, type = file.ContentType, url = "/AdditionalInfo/DownloadNotesInfo?messageId=" + messageId + "&appendixId=" + document._id, thumbnail_url = @"data:image/png;base64," + EncodeFile(physicalPath), delete_type = "GET", }); } return(Json(statuses)); }