protected void ReadFileContents(ClientProjectDocument document) { using (FileStream fs = new FileStream(Path.GetTempFileName(), FileMode.Create)) { document.File.CopyTo(fs); document.FileContents = new byte[fs.Length]; fs.Read(document.FileContents, 0, (int)fs.Length); } }
protected void PopulateTags(ClientProjectDocument document) { if (document.TagsString.Length > 0) { string[] splits = document.TagsString.Split(new string[] { ", " }, StringSplitOptions.None); List <string> uniqueTags = splits.Select(t => t.ToLower()).ToList(); uniqueTags = uniqueTags.Distinct().ToList(); foreach (string tag in uniqueTags) { document.Tags.Add(tag); } } }
public IActionResult UploadDocument(ClientProjectDocument document) { try { if (ModelState.IsValid) { MakeProjectDocument(document); return(RedirectToAction("Project", "Projects", new { projectId = document.ProjectId })); } else { throw new DBWriteException("Votre fichier n'a pas pu être chargé."); } } catch (BTPBException ex) { return(RedirectToAction("Index", "Projects")); } }
protected void MakeProjectDocument(ClientProjectDocument document) { PopulateTags(document); document.FileContents = UploadFile(document.File); ProjectDocument _document = new ProjectDocument(document.ProjectId, document.Title, document.TypeKey, document.Description, document.Tags); _document.Save(); foreach (string tagText in document.Tags) { Tag tag = new Tag(tagText); tag.Save(); ProjectDocumentTag docTag = new ProjectDocumentTag(_document.Id, tag); docTag.Save(); } ProjectDocumentContentTypeCode _contentType = null; try { _contentType = new ProjectDocumentContentTypeCode(document.File.ContentType); } catch { _contentType = new ProjectDocumentContentTypeCode() { Title = document.File.ContentType, Key = document.File.ContentType, Active = true, Order = 0 }; _contentType.Save(); } ProjectDocumentContent content = new ProjectDocumentContent(_document.Id, document.File.FileName, document.FileContents, _contentType.Id); content.Save(); }