public void DeleteAttachment(Attachment attachment) { string filePath = Path.Combine(HostingEnvironment.MapPath(DirectoryPaths.Attachments), attachment.SavedName); if (System.IO.File.Exists(filePath)) System.IO.File.Delete(filePath); _attachmentRepository.Delete(attachment.AttachmentID); _unitOfWork.Commit(); }
public void CreateAttachment(HttpPostedFileBase file, int PostID) { string savedName = UploadFile(file); var attachment = new Attachment { Downloaded = 0, SavedName = savedName, DownloadName = file.FileName, PostID = PostID, Size = file.ContentLength, Type = file.ContentType }; _attachmentRepository.Add(attachment); _unitOfWork.Commit(); }