public String GetFullPath(AttachmentOwner ownerType) { if (ownerType == AttachmentOwner.Employees) { return("UploadEm"); } if (ownerType == AttachmentOwner.Customers) { return("UploadCus"); } if (ownerType == AttachmentOwner.Projects) { return("UploadProj"); } if (ownerType == AttachmentOwner.Tasks) { return("UploadTask"); } else { //var year = AppHelper.ThisYear; //var Month = AppHelper.ThisMonth; //return AppHelper.UploadIconLanguages; return("UploadDefault"); } }
public List <Attachment> GetPhoto(string ownerId, AttachmentOwner ownerType) { var file = _context.Attachments.Where(x => x.OwnerId == ownerId && x.AttachmentOwner == ownerType).ToList(); return(file); }
public String GetFileName(IFormFile file, AttachmentOwner ownerType) { if (ownerType == AttachmentOwner.Employees) { return(file.FileName); } else { return(file.FileName); } }
public static Attachment ToAttachment(this IFormFile source, string ownerId, AttachmentOwner ownerType, AttachmentType attachmentType, string fileName) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(new Attachment() { FileName = fileName, FileExtenstion = Path.GetExtension(fileName), OwnerId = ownerId, AttachmentOwner = ownerType, CreationDate = DateTime.Now }); }
public bool OnPostUpload(List <IFormFile> files, string recordId, AttachmentOwner ownerType, AttachmentType attachmentType, string WebRootPath) { if (files != null && files.Count > 0) { string folderName = GetFullPath(ownerType); string webRootPath = WebRootPath; string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } foreach (IFormFile item in files) { if (item.Length > 0) { string fileName = GetFileName(item, ownerType); string fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { item.CopyTo(stream); } var attachment = item.ToAttachment(recordId, ownerType, attachmentType, fileName); if (attachment != null) { AddToDb(attachment); } } } return(true); } return(false); }
public static bool ContainsFile(string AttachmentName, AttachmentOwner attachmentOwner, string WebRootPath) { if (attachmentOwner == AttachmentOwner.Tasks) { string folderName = AppHelper.UploadTask; string webRootPath = WebRootPath; string newPath = Path.Combine(webRootPath, folderName); var tempFolderInfolang = $"{newPath}/{AttachmentName}"; if (File.Exists(tempFolderInfolang)) { File.Delete(tempFolderInfolang); return(true); } return(false); } if (attachmentOwner == AttachmentOwner.Employees) { string folderName = AppHelper.UploadEmp; string webRootPath = WebRootPath; string newPath = Path.Combine(webRootPath, folderName); var tempFolderInfolang = $"{newPath}/{AttachmentName}"; if (File.Exists(tempFolderInfolang)) { File.Delete(tempFolderInfolang); return(true); } return(false); } if (attachmentOwner == AttachmentOwner.Customers) { string folderName = AppHelper.UploadCut; string webRootPath = WebRootPath; string newPath = Path.Combine(webRootPath, folderName); var tempFolderInfolang = $"{newPath}/{AttachmentName}"; if (File.Exists(tempFolderInfolang)) { File.Delete(tempFolderInfolang); return(true); } return(false); } if (attachmentOwner == AttachmentOwner.Projects) { string folderName = AppHelper.UploadPro; string webRootPath = WebRootPath; string newPath = Path.Combine(webRootPath, folderName); var tempFolderInfolang = $"{newPath}/{AttachmentName}"; if (File.Exists(tempFolderInfolang)) { File.Delete(tempFolderInfolang); return(true); } return(false); } else { return(false); } }