/// <summary> /// Creates the digital file view. /// </summary> /// <param name="digitalFileView">The digital file view.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">digitalFileView</exception> public IDigitalFileView CreateUploadExcelView(IDigitalFileView digitalFileView, string processingMessage, IList <IFileType> fileType) { if (digitalFileView == null) { throw new ArgumentException("digitalFileView"); } var fileTypeDDL = GetFileTypeDropdown.GetFileTypes(fileType, -1); digitalFileView.ProcessingMessage = processingMessage; digitalFileView.FileTypeList = fileTypeDDL; return(digitalFileView); }
public string ProcessUploadExcelMainInfo(HttpPostedFileBase excelSheet, IDigitalFileView digitalFileView) { // save files uploaded by calling digital file services, the id returned will be zero if no files are uploaded - no need to check anything here var processingExcelMessage = digitalFileServices.SaveFile(FileType.Image, excelSheet, digitalFileView); // check that both files saved correctly if (!string.IsNullOrEmpty(processingExcelMessage)) { var message = string.Format("{0}", processingExcelMessage); return(message); } return(processingExcelMessage); }
/// <summary> /// Saves the digital file. /// </summary> /// <param name="digitalFileTypeId">The digital file type identifier.</param> /// <param name="fileName">Name of the file.</param> /// <param name="fileExtension">The file extension.</param> /// <param name="contentType">Type of the content.</param> /// <param name="theContent">The content.</param> /// <param name="digitalFileId">The digital file identifier.</param> /// <returns></returns> public string SaveDigitalFile(int digitalFileTypeId, string fileName, string fileExtension, string contentType, byte[] theContent, IDigitalFileView digitalFileView) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (string.IsNullOrEmpty(contentType)) { throw new ArgumentNullException(nameof(contentType)); } if (theContent == null) { throw new ArgumentNullException(nameof(theContent)); } var result = string.Empty; var newRecord = new DigitalFile { FileTypeId = digitalFileView.FileTypeId, FileContent = theContent, FileExtension = fileExtension, FileName = fileName, ContentType = contentType, DigitalTypeId = digitalFileTypeId, IsActive = true, DateCreated = DateTime.Now }; try { using ( var dbContext = (PitalyticsEntities)this.dbContextFactory.GetDbContext()) { var fileInfo = dbContext.DigitalFiles.SingleOrDefault(x => x.FileTypeId == newRecord.FileTypeId && x.IsActive == true); if (fileInfo != null) { fileInfo.IsActive = false; } dbContext.DigitalFiles.Add(newRecord); dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("SaveDigitalFile - {0} , {1}", e.Message, e.InnerException != null ? e.InnerException.Message : ""); } return(result); }
/// <summary> /// Saves the file. /// </summary> /// <param name="digitalFileTypeId">The digital file type identifier.</param> /// <param name="profilePicture">The profile picture.</param> /// <returns></returns> public string SaveFile(int digitalFileTypeId, HttpPostedFileBase profilePicture, IDigitalFileView digitalFileView) { var processingMessage = string.Empty; if ((profilePicture == null) || (profilePicture.ContentLength < 1)) { return(processingMessage); } byte[] theContent; using (Stream inputStream = profilePicture.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } theContent = memoryStream.ToArray(); } var fileName = profilePicture.FileName; var contentType = profilePicture.ContentType; var fileExtension = fileName.FileExtension(); processingMessage = this.digitalFileRepository.SaveDigitalFile(digitalFileTypeId, fileName, fileExtension, contentType, theContent, digitalFileView); return(processingMessage); }
/// <summary> /// Gets the upload excel view. /// </summary> /// <param name="digitalFileView">The digital file view.</param> /// <param name="processingMessage">The processing message.</param> /// <returns></returns> public IDigitalFileView GetUploadExcelView(IDigitalFileView digitalFileView, string processingMessage) { var fileType = this.generalRepository.GetFileType(); return(this.generalFactory.CreateUploadExcelView(digitalFileView, processingMessage, fileType)); }