public Result DeleteAccessFile(string fileCoverID, string accessFileName, string account) { Result result = new Result(); try { Guid g = new Guid(fileCoverID); PCBEntities pCBEntities = new PCBEntities(); PCB_AccessFileTB pCB_AccessFileTB = pCBEntities.PCB_AccessFileTB.FirstOrDefault(p => p.CreateAccount == account && p.FileCoverID == g && p.AccessFileName == accessFileName); // pCBEntities.PCB_AccessFileTB.FirstOrDefault(p => p.FileCoverID == new Guid(fileCoverID) && p.CreateAccount == account && p.FileExtension == fileExtension); if (pCB_AccessFileTB == null || pCB_AccessFileTB == default(PCB_AccessFileTB)) { result.IsOK = false; result.Description = "找不到对应的附件"; return(result); } pCBEntities.DeleteObject(pCB_AccessFileTB); result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges()); if (!result.IsOK) { result.Description = "删除失败"; return(result); } string saveToUrl = @ParameterAPI.GetConfig("FileURL").ConfigValue + @"\\" + account + @"\\" + fileCoverID + @"\\" + accessFileName + "." + pCB_AccessFileTB.FileExtension; File.Delete(saveToUrl); } catch (Exception ex) { LogHelper.WriteLog(GetType()).Info(ex.StackTrace); result.IsOK = false; result.Description = ex.InnerException.Message; } return(result); }
public Result UploadAccessFile(byte[] accessFile, string fileCoverID, string account, string fileExtension, string accessFileName) { Result result = new Result(); string saveToUrl = @ParameterAPI.GetConfig("FileURL").ConfigValue + @"\\" + account + @"\\" + fileCoverID + @"\\" + accessFileName + "." + fileExtension; try { Guid g = new Guid(fileCoverID); PCBEntities pCBEntities = new PCBEntities(); int count = pCBEntities.PCB_FileCoverTB.Count <PCB_FileCoverTB>(p => p.FileCoverID == g); if (count <= 0) { result.IsOK = false; result.Description = "封面ID不存在"; return(result); } PCB_AccessFileTB pCB_AccessFileTB = pCBEntities.PCB_AccessFileTB.FirstOrDefault(p => p.CreateAccount == account && p.FileExtension == fileExtension && p.FileCoverID == g && p.AccessFileName == accessFileName);// pCBEntities.PCB_AccessFileTB.FirstOrDefault(p => p.FileCoverID == new Guid(fileCoverID) && p.CreateAccount == account && p.FileExtension == fileExtension); if (pCB_AccessFileTB != null || pCB_AccessFileTB != default(PCB_AccessFileTB)) { result.IsOK = false; result.Description = "上传的文件已经存在"; return(result); } //string fileName=Guid.NewGuid().ToString(); result = Common.Common.FileWrite(saveToUrl, accessFile); if (!result.IsOK) { return(result); } pCB_AccessFileTB = new PCB_AccessFileTB(); pCB_AccessFileTB.AccessFileID = Guid.NewGuid(); pCB_AccessFileTB.AccessFileName = accessFileName; pCB_AccessFileTB.FileCoverID = new Guid(fileCoverID); pCB_AccessFileTB.AccessFileURL = ParameterAPI.GetConfig("DowLoadFileURL").ConfigValue + "//" + account + "//" + fileCoverID + "//" + accessFileName + "." + fileExtension; pCB_AccessFileTB.FileExtension = fileExtension; pCB_AccessFileTB.CreateAccount = account; pCB_AccessFileTB.FileMD5 = Common.Common.GetMD5Hash(accessFile); pCB_AccessFileTB.FileSize = accessFile.Length.ToString(); pCB_AccessFileTB.CreateDateTime = DateTime.Now; pCBEntities.AddToPCB_AccessFileTB(pCB_AccessFileTB); result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges()); if (!result.IsOK) { File.Delete(saveToUrl); result.Description = "上传失败"; return(result); } //Bitmap bmp = new Bitmap(Imagefilename); //MemoryStream ms = new MemoryStream(); //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //byte[] arr = new byte[ms.Length]; //ms.Position = 0; //ms.Read(arr, 0, (int)ms.Length); //ms.Close(); //string r = Convert.ToBase64String(arr); //Result ret = UpdateFileCover(r, "chenc"); } catch (Exception ex) { File.Delete(saveToUrl); LogHelper.WriteLog(GetType()).Info(ex.StackTrace); result.IsOK = false; result.Description = ex.InnerException.Message; } return(result); }