public FileUploadJsonResult AjaxUploadAFile(HttpPostedFileBase file) { string strMessage = AppConstants.FileUploadSuccess; bool isFileUploaded = true; string attachmentUrl = String.Empty; if (file == null) { return new FileUploadJsonResult { Data = new { strUploadMessage = AppConstants.FileUploadNoFileSelected, isSuccessfulUpload = false } }; } //To validate for standard image formats .pdf .jpeg .png .gif .bmp if (AppCommon.IsValidImageFormatForSimOffice(file.ContentType)) { int fileSize = Convert.ToInt32(ConfigurationManager.AppSettings["SimOfficeMaxFileSize"]); try { //To validate for standard image size - 3 MB if (file.ContentLength <= fileSize) { byte[] fileByteToBeSaved = new byte[file.ContentLength]; file.InputStream.Read(fileByteToBeSaved, 0, file.ContentLength); Attachment uploadedFile = new Attachment { FileType = file.ContentType, FileName = String.IsNullOrEmpty(file.FileName) ? AppConstants.StandardFileName : file.FileName.Split('\\').Last(), FileContent = fileByteToBeSaved, IsActive = true, IsAutoSave = true }; SetAuditFields(uploadedFile, false); _questionBankService.SaveAttachment(string.Empty, uploadedFile, true, out attachmentUrl); } else { strMessage = AppConstants.FileUploadError; isFileUploaded = false; } } catch { strMessage = AppConstants.FileUploadFailure; isFileUploaded = false; } } else { strMessage = AppConstants.FileUploadError; isFileUploaded = false; } return new FileUploadJsonResult { Data = new { strUploadMessage = strMessage, isSuccessfulUpload = isFileUploaded, imageRefId = Convert.ToString(attachmentUrl) } }; }
//public Question GetQuestionWithGuid(string strGuid) //{ // string _questionDocumentUrl = ""; // _questionDocumentUrl = string.Format(_questionDocument.GetAssignmentUrl(), strGuid); // return _questionDocument.Get(_questionDocumentUrl); //} /// <summary> /// to get question with guid /// </summary> /// <returns></returns> /// <summary> /// to save the image /// </summary> /// <param name="attachmentGuid"></param> /// <param name="attachmentObject"></param> /// <param name="isTransient"> </param> /// <param name="attachmentUrl"></param> /// <returns></returns> public bool SaveAttachment(string attachmentGuid, Attachment attachmentObject, bool isTransient, out string attachmentUrl) { attachmentUrl = isTransient ? _attachmentDocument.GetAssignmentUrl(DocumentPath.Module.Attachments,AppConstants.TransientAttachment) : _attachmentDocument.GetAssignmentUrl(DocumentPath.Module.Attachments); attachmentUrl = _attachmentDocument.SaveOrUpdate(attachmentUrl, attachmentObject); return true; }