public Result FileIsPublish(string fileCoverID, string account, string setPrice, int publishStatus)
        {
            Result result = new Result();

            try
            {
                Guid            g               = new Guid(fileCoverID);
                PCBEntities     pCBEntities     = new PCBEntities();
                PCB_FileCoverTB pCB_FileCoverTB = pCBEntities.PCB_FileCoverTB.FirstOrDefault(p => p.FileCoverID == g && p.CreateAccount == account);
                if (pCB_FileCoverTB == null || pCB_FileCoverTB == default(PCB_FileCoverTB))
                {
                    result.IsOK        = false;
                    result.Description = "找不到该文件信息";
                    return(result);
                }
                pCB_FileCoverTB.Price          = setPrice;
                pCB_FileCoverTB.IsPublish      = Convert.ToBoolean(publishStatus);
                pCB_FileCoverTB.UpdateDateTime = DateTime.Now;
                pCBEntities.Refresh(System.Data.Objects.RefreshMode.ClientWins, pCB_FileCoverTB);
                result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges());
                if (!result.IsOK)
                {
                    result.Description = "发布失败";
                    return(result);
                }
                result.Description = "发布成功";
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }
        public Result EditFileCover(string fileCoverID, string fileExtension, string fileCoverName, string account, Byte[] newFileData)
        {
            string saveToUrl = "";
            Result result    = new Result();

            try
            {
                Guid            g               = new Guid(fileCoverID);
                PCBEntities     pCBEntities     = new PCBEntities();
                PCB_FileCoverTB pCB_FileCoverTB = pCBEntities.PCB_FileCoverTB.FirstOrDefault(p => p.FileCoverID == g && p.CreateAccount == account);
                if (pCB_FileCoverTB == null || pCB_FileCoverTB == default(PCB_FileCoverTB))
                {
                    result.IsOK        = false;
                    result.Description = "找不到该文件信息";
                    return(result);
                }
                String dir    = @ParameterAPI.GetConfig("FileURL").ConfigValue + @"\\" + account + @"\\" + fileCoverID;
                string oldUrl = dir + @"\\" + pCB_FileCoverTB.FileCoverName + "." + pCB_FileCoverTB.FileExtension;
                if (string.IsNullOrEmpty(fileCoverName))
                {
                    pCB_FileCoverTB.FileCoverName = fileCoverName;
                }
                if (newFileData.Length > 0)
                {
                    pCB_FileCoverTB.FileSize     = newFileData.Length.ToString();
                    pCB_FileCoverTB.FileMD5      = Common.Common.GetMD5Hash(newFileData);
                    pCB_FileCoverTB.FileCoverURL = ParameterAPI.GetConfig("DowLoadFileURL").ConfigValue + "//" + account + "//" + g + "//" + fileCoverName + "." + fileExtension;

                    saveToUrl = dir + @"\\" + fileCoverName + "." + fileExtension;
                    result    = Common.Common.FileWrite(saveToUrl, newFileData);
                    if (!result.IsOK)
                    {
                        return(result);
                    }
                    pCB_FileCoverTB.UpdateDateTime = DateTime.Now;
                    pCBEntities.Refresh(System.Data.Objects.RefreshMode.ClientWins, pCB_FileCoverTB);
                    result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges());
                    if (!result.IsOK)
                    {
                        File.Delete(saveToUrl);
                        result.Description = "编辑失败";
                        return(result);
                    }
                    File.Delete(oldUrl);
                    result.Description = "编辑成功";
                }
            }
            catch (Exception ex)
            {
                File.Delete(saveToUrl);
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }
        public Result UploadFileCover(Byte[] fileData, string account, string fileExtension, string fileCoverName)
        {
            Result result = new Result();

            try
            {
                //byte[] coverPhoto = Convert.FromBase64String(fileData);
                //MemoryStream ms = new MemoryStream(coverPhoto);
                //Bitmap bmp = new Bitmap(ms);

                PCB_FileCoverTB pCB_FileCoverTB = new PCB_FileCoverTB();
                pCB_FileCoverTB.FileCoverID    = System.Guid.NewGuid();
                pCB_FileCoverTB.FileCoverName  = fileCoverName;
                pCB_FileCoverTB.FileMD5        = Common.Common.GetMD5Hash(fileData);
                pCB_FileCoverTB.FileExtension  = fileExtension;
                pCB_FileCoverTB.FileSize       = fileData.Length.ToString();
                pCB_FileCoverTB.IsPublish      = false;
                pCB_FileCoverTB.FileCoverURL   = ParameterAPI.GetConfig("DowLoadFileURL").ConfigValue + "//" + account + "//" + pCB_FileCoverTB.FileCoverID.ToString() + "//" + pCB_FileCoverTB.FileCoverName + "." + fileExtension;
                pCB_FileCoverTB.CreateAccount  = account;
                pCB_FileCoverTB.CreateDateTime = DateTime.Now;


                String dir = @ParameterAPI.GetConfig("FileURL").ConfigValue + @"\\" + account + @"\\" + pCB_FileCoverTB.FileCoverID.ToString();
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                string saveToUrl = dir + @"\\" + pCB_FileCoverTB.FileCoverName + "." + fileExtension;
                result = Common.Common.FileWrite(saveToUrl, fileData);
                if (!result.IsOK)
                {
                    return(result);
                }
                //bmp.Save(saveDir);
                //bmp.Dispose();
                //ms.Close();
                PCBEntities pCBEntities = new PCBEntities();
                pCBEntities.AddToPCB_FileCoverTB(pCB_FileCoverTB);
                result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges());
                if (!result.IsOK)
                {
                    Directory.Delete(dir, true);
                    result.Description = "上传失败";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }
        public Result DeleteFileCover(string fileCoverID, string account)
        {
            Result result = new Result();

            try
            {
                Guid            g               = new Guid(fileCoverID);
                PCBEntities     pCBEntities     = new PCBEntities();
                PCB_FileCoverTB pCB_FileCoverTB = pCBEntities.PCB_FileCoverTB.FirstOrDefault(p => p.FileCoverID == g && p.CreateAccount == account);
                if (pCB_FileCoverTB == null || pCB_FileCoverTB == default(PCB_FileCoverTB))
                {
                    result.IsOK        = false;
                    result.Description = "找不到该文件信息";
                    return(result);
                }
                pCBEntities.DeleteObject(pCB_FileCoverTB);
                IQueryable <PCB_AccessFileTB> queryable = pCBEntities.PCB_AccessFileTB.Where(p => p.FileCoverID == g && p.CreateAccount == account);
                foreach (var item in queryable)
                {
                    pCBEntities.DeleteObject(item);
                }
                result.IsOK = Convert.ToBoolean(pCBEntities.SaveChanges());
                if (!result.IsOK)
                {
                    result.Description = "删除失败";
                    return(result);
                }
                string saveToUrl = @ParameterAPI.GetConfig("FileURL").ConfigValue + @"\\" + account + @"\\" + fileCoverID;
                Directory.Delete(saveToUrl, true);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.InnerException.Message;
            }
            return(result);
        }
Exemplo n.º 5
0
        public Result CheckAndPreCreate(string account, string filecoverID)
        {
            Result result = new Result();

            try
            {
                result.IsOK = true;

                PCBEntities     pcbEntities    = new PCBEntities();
                Guid            fid            = new Guid(filecoverID);
                PCB_FileCoverTB pcbfilecoverTB = pcbEntities.PCB_FileCoverTB.FirstOrDefault(p => p.FileCoverID == fid);
                if (pcbfilecoverTB == null)
                {
                    result.IsOK        = false;
                    result.Description = "未查询到指定数据";
                    return(result);
                }
                var accessFileList = from accessfile in pcbEntities.PCB_AccessFileTB
                                     where accessfile.FileCoverID == fid
                                     select new
                {
                    AccessFileName = accessfile.AccessFileName,
                    AccessFileURL  = accessfile.AccessFileURL,
                    FileExtension  = accessfile.FileExtension,
                    FileSize       = accessfile.FileSize,
                    FileMD5        = accessfile.FileMD5
                };
                decimal filecoverprice;
                if (decimal.TryParse(pcbfilecoverTB.Price, out filecoverprice))
                {
                    if (filecoverprice > 0)
                    {
                        //金额>0,查询预下单记录
                        LogHelper.WriteLog(GetType()).Info(filecoverprice.ToString());

                        PCB_OrderTB pcborderTB = pcbEntities.PCB_OrderTB.FirstOrDefault(p => p.FileCoverID == fid);
                        if (pcborderTB != null)
                        {
                            //LogHelper.WriteLog(GetType()).Info(pcborderTB);
                            //有记录
                            if (pcborderTB.IsPay)
                            {
                                result.Description = "文件已支付,返回数据类型为:文件下载地址";

                                result.ExtData = JsonConvert.SerializeObject(accessFileList);
                            }
                            else
                            {
                                result = PreCreate(account, filecoverID);
                                //result.Description = "文件需支付,返回数据类型为:文件价格";
                                //result.ExtData = pcbfilecoverTB.Price;
                                //pcbEntities.DeleteObject(pcborderTB);
                                //pcbEntities.SaveChanges();
                            }
                        }
                        else
                        {
                            //LogHelper.WriteLog(GetType()).Info(pcborderTB);
                            //result.ExtData = pcbfilecoverTB.Price;
                            //result.Description = "文件需支付,返回数据类型为:文件价格";
                            result = PreCreate(account, filecoverID);
                        }
                    }
                    else
                    {
                        //金额==0,返回下载地址
                        LogHelper.WriteLog(GetType()).Info(filecoverprice.ToString());
                        result.ExtData     = JsonConvert.SerializeObject(accessFileList);
                        result.Description = "文件无需支付,返回数据类型为:文件下载地址";
                    }
                }
                else
                {
                    throw new Exception("封面金额转换错误,pcbfilecoverTB.Price : " + pcbfilecoverTB.Price);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.Message;
            }
            return(result);
        }