private async Task AddDocumentsAsync(Posting posting, List <IFormFile> theFiles) { foreach (var f in theFiles) { if (f != null) { string mimeType = f.ContentType; string fileName = Path.GetFileName(f.FileName); long fileLength = f.Length; //Note: you could filter for mime types if you only want to allow //certain types of files. I am allowing everything. if (!(fileName == "" || fileLength == 0))//Looks like we have a file!!! { PostingDocument d = new PostingDocument(); using (var memoryStream = new MemoryStream()) { await f.CopyToAsync(memoryStream); d.FileContent.Content = memoryStream.ToArray(); } d.MimeType = mimeType; d.FileName = fileName; posting.PostingDocuments.Add(d); } ; } } }
//Broke the Populate approach down into 2 methods for future use. private void PopulateDropDownLists(PostingDocument postingDocument = null) { ViewData["PostingID"] = PostingSelectList(postingDocument?.PostingID); }