public void CreateGoods()
 {
     FxGoodsContext context = new FxGoodsContext();
     var entity = new Entity.FxGoods.GoodsTransferInfo()
     {
         Action = "Action",
         AreaId = 1,
         ChangeMsg = "ChangeMsg",
         GoodsConditionMsg = "GoodsConditionMsg",
         GoodsconditonId = 1,
         IsChange = false,
         CatagroyId = 1,
         CityId = 1,
         Controller = "Controller",
         IsDelete = false,
         IsPublish = false,
         Mark = "Mark",
         Pictures = new System.Collections.Generic.List<Entity.TransferPicture>() { 
             new Entity.TransferPicture() { 
                  CdnUrl="CdnUrl", ImageUrl="CdnUrl", IsCdn=false, PhysicalPath="CdnUrl", TransferPictureCatagroy=2
             } 
         },
         Price = 1232,
         PublishTitle = "PublishTitle",
         PublishUserEmail = "PublishUserEmail",
         UserAccount = "UserAccount"
     };
     context.GoodsTransferInfos.Add(entity);
     context.SaveChanges();
     context.GoodsTransferInfos.Remove(entity);
     context.SaveChanges();
 }
 public int InfoCount()
 {
     using (var context = new FxGoodsContext())
     {
         return context.GoodsBuyInfos.Count() + context.GoodsTransferInfos.Count();
     }
 }
 /// <summary>
 /// 获取物品求购信息
 /// </summary>
 /// <param name="Id">物品求购Id</param>
 /// <returns>物品求购信息</returns>
 public Entity.FxGoods.GoodsBuyInfo Get(int Id)
 {
     using (FxGoodsContext context = new FxGoodsContext())
     {
         return context.GoodsBuyInfos.Include(r=>r.Pictures)
             .Where(r => r.GoodsBuyInfoId == Id).FirstOrDefault();
     }
 }
 /// <summary>
 /// 保存物品求购信息
 /// </summary>
 /// <param name="goods">物品求购信息</param>
 /// <returns>是否保存成功</returns>
 public bool SaveBuyGoods(Entity.FxGoods.GoodsBuyInfo goods)
 {
     using (FxGoodsContext context = new FxGoodsContext())
     {
         context.GoodsBuyInfos.Add(goods);
         context.SaveChanges();
     }
     return goods.GoodsBuyInfoId > 0;
 }
 public bool SaveTransferGoods(GoodsTransferInfo goods)
 {
     using (FxGoodsContext context = new FxGoodsContext())
     {
         context.GoodsTransferInfos.Add(goods);
         context.SaveChanges();
     }
     return goods.GoodsTransferInfoId > 0;
 }
 public List<GoodsTransferInfo> HomeSupplies()
 {
     List<GoodsTransferInfo> list;
     using (FxGoodsContext context = new FxGoodsContext())
     {
         list = context.GoodsTransferInfos.Include(r => r.Pictures)
                  .Where(r => r.IsPublish == true && r.Action == "HomeSupplies")
                  .OrderByDescending(r => r.CreatedTime)
                  .Take(20).ToList();
     }
     if ((list.Count % 4) != 0)
     {
         return list.Take(list.Count - list.Count % 4).ToList();
     }
     return list;
 }
 /// <summary>
 /// 认证成功
 /// </summary>
 /// <param name="goodsId">物品求购帖子Id</param>
 /// <returns>是否成功</returns>
 public bool AuthorizeSuccess(int goodsId)
 {
     using (var context = new FxGoodsContext())
     {
         var goods = context.GoodsBuyInfos.Where(r => r.GoodsBuyInfoId == goodsId).FirstOrDefault();
         if (goods != null)
         {
             goods.InfoProcessState = (int)ProcessState.AuthorizeSuccess;
             goods.Logs.Add(new Entity.FxGoods.GoodsBuyLog()
             {
                 OperteName = Enum.GetName(typeof(ProcessState), ProcessState.AuthorizeSuccess)
             });
             return context.SaveChanges() > 0;
         }
     }
     return false;
 }
 public void LoadJob()
 {
     try
     {
         List<int> list = new List<int>();
         using (var context = new FxGoodsContext())
         {
             list = context.GoodsTransferInfos
                  .Where(r => r.InfoProcessState == (int)ProcessState.Commit).
                      Select(r => r.GoodsTransferInfoId).Take(20).ToList();
         }
         JobQueue.GoodsTransferJobLoadQueue.AddRange(list);
     }
     catch (Exception ex)
     {
         ex.LogEx(string.Format("{0} {1}", JobKey, "GoodsTransferJobLoad"));
     }
 }
 public bool PictrueCdning(int goodsId)
 {
     using (var context = new FxGoodsContext())
     {
         var goods = context.GoodsTransferInfos.Where(r => r.GoodsTransferInfoId == goodsId).FirstOrDefault();
         if (goods != null)
         {
             goods.InfoProcessState = (int)ProcessState.PictrueCdning;
             goods.IsPublish = true;
             goods.Logs.Add(new Entity.FxGoods.GoodsTransferLog()
             {
                 OperteName = Enum.GetName(typeof(ProcessState), ProcessState.PictrueCdning)
             });
             return context.SaveChanges() > 0;
         }
     }
     return false;
 }
 public bool AuthorizeFaild(int goodsId,string msg)
 {
     using (var context = new FxGoodsContext())
     {
         var goods = context.GoodsTransferInfos.Where(r => r.GoodsTransferInfoId == goodsId).FirstOrDefault();
         if (goods != null)
         {
             goods.InfoProcessState = (int)ProcessState.AuthorizeFaild;
             goods.ErrorMsg = msg;
             goods.Logs.Add(new Entity.FxGoods.GoodsTransferLog()
             {
                 OperteName = Enum.GetName(typeof(ProcessState), ProcessState.AuthorizeFaild)
             });
             return context.SaveChanges() > 0;
         }
     }
     return false;
 }
 /// <summary>
 /// 图片CDN失败
 /// </summary>
 /// <param name="goodsId">物品转让帖子Id</param>
 /// <param name="errorMsg">图片CDN失败错误信息</param>
 /// <returns>操作是否成功</returns>
 public bool PictrueCdnFailed(int goodsId, string errorMsg)
 {
     using (var context = new FxGoodsContext())
     {
         var goods = context.GoodsTransferInfos.Where(r => r.GoodsTransferInfoId == goodsId).FirstOrDefault();
         if (goods != null)
         {
             goods.InfoProcessState = (int)ProcessState.PictrueCdnFailed;
             goods.Logs.Add(new Entity.FxGoods.GoodsTransferLog()
             {
                 OperteName = Enum.GetName(typeof(ProcessState), ProcessState.PictrueCdnFailed)
             });
             context.PictureCdnErrors.Add(new PictureCdnError()
             {
                 ErorMsg    = errorMsg,
                 ObjectId   = goodsId,
                 SourceType = (int)ChannelCatagroy.FxGoodsTransfer
             });
             return(context.SaveChanges() > 0);
         }
     }
     return(false);
 }
 public void Authorize()
 {
     int id = JobQueue.GoodsTransferJobLoadQueue.GetItem(goodsTransferJobService.Authorizing);
     if (id == 0)
     {
         return;
     }
     using (var context = new FxGoodsContext())
     {
         while (id != 0)
         {
             var goods = context.GoodsTransferInfos.Where(r => r.GoodsTransferInfoId == id).
                     Select(r => new { r.Mark, r.PublishTitle,r.GoodsConditionMsg }).FirstOrDefault();
             if (goods != null)
             {
                 if (filter.FilterContent(goods.Mark).Success &&
                     filter.FilterContent(goods.PublishTitle).Success &&
                     filter.FilterContent(goods.GoodsConditionMsg).Success)
                 {
                     try
                     {
                         goodsTransferJobService.AuthorizeSuccess(id);
                         JobQueue.GoodsTransferJobPictureProcessQueue.Add(id);
                     }
                     catch (Exception ex)
                     {
                         ex.LogEx(string.Format("{0} {1} {2}", JobKey, "goodsTransferJobService.AuthorizeSuccess", id));
                     }
                 }
                 else
                 {
                     try
                     {
                         string msg = "";
                         var filter1 = filter.FilterContent(goods.Mark);
                         var filter2 = filter.FilterContent(goods.PublishTitle);
                         var filter3 = filter.FilterContent(goods.GoodsConditionMsg);
                         if (!filter1.Success)
                         {
                             msg += string.Format("你的帖子中包含了[[{0}]] 这个关键字", filter1.Key);
                         }
                         if (!filter2.Success)
                         {
                             msg += string.Format("你的帖子中包含了[[{0}]] 这个关键字", filter2.Key);
                         }
                         if (!filter3.Success)
                         {
                             msg += string.Format("你的帖子中包含了[[{0}]] 这个关键字", filter3.Key);
                         }
                         goodsTransferJobService.AuthorizeFaild(id, msg);
                     }
                     catch (Exception ex)
                     {
                         ex.LogEx(string.Format("{0} {1} {2}", JobKey, "goodsTransferJobService.AuthorizeFaild", id));
                     }
                 }
                 id = JobQueue.GoodsTransferJobLoadQueue.GetItem(goodsTransferJobService.Authorizing);
             }
         }
     }
 }
 /// <summary>
 /// 图片CDN失败
 /// </summary>
 /// <param name="goodsId">物品求购帖子Id</param>
 /// <param name="errorMsg">CDN失败错误信息</param>
 /// <returns>是否成功</returns>
 public bool PictrueCdnFailed(int goodsId, string errorMsg)
 {
     using (var context = new FxGoodsContext())
     {
         var goods = context.GoodsBuyInfos.Where(r => r.GoodsBuyInfoId == goodsId).FirstOrDefault();
         if (goods != null)
         {
             goods.InfoProcessState = (int)ProcessState.PictrueCdnFailed;
             goods.Logs.Add(new Entity.FxGoods.GoodsBuyLog()
             {
                 OperteName = Enum.GetName(typeof(ProcessState), ProcessState.PictrueCdnFailed)
             });
             context.PictureCdnErrors.Add(new PictureCdnError()
             {
                 ErorMsg = errorMsg,
                 ObjectId = goodsId,
                 SourceType = (int)ChannelCatagroy.FxGoodsBuy
             });
             return context.SaveChanges() > 0;
         }
     }
     return false;
 }
 public void PictureProcess()
 {
     int goodsId = JobQueue.GoodsTransferJobPictureProcessQueue.GetItem(goodsTransferJobService.PictrueCdning);
     if (goodsId == 0)
     {
         return;
     }
     using (var context = new FxGoodsContext())
     {
         while (goodsId != 0)
         {
             var car = context.GoodsTransferInfos.Where(r => r.GoodsTransferInfoId == goodsId).FirstOrDefault();
             if (car != null)
             {
                 string source;
                 string destnation;
                 string destnationmin;
                 int error = 0;
                 string errmsg = "";
                 foreach (var picture in car.Pictures)
                 {
                     try
                     {
                         source = string.Format(picture.PhysicalPath);
                         destnation = string.Format("{0}{1}", appSettings.CdnPath(), picture.ImageUrl.Replace(@"/", @"\"));
                         destnationmin = string.Format("{0}{1}", appSettings.CdnPath(), picture.MinImageUrl.Replace(@"/", @"\"));
                         var job = new ImageJob(source, destnation, new ResizeSettings()
                         {
                             MaxHeight = 500,
                             MaxWidth = 500,
                         }) { CreateParentDirectory = true };
                         var jobmin = new ImageJob(source, destnationmin, new ResizeSettings()
                         {
                             MaxHeight = 64,
                             MaxWidth = 64,
                         }) { CreateParentDirectory = true };
                         ImageBuilder.Current.Build(job);
                         ImageBuilder.Current.Build(jobmin);
                     }
                     catch (Exception ex)
                     {
                         if (string.IsNullOrEmpty(errmsg))
                         {
                             if (ex.InnerException != null)
                             {
                                 errmsg = ex.InnerException.Message;
                             }
                             else
                             {
                                 errmsg = ex.Message;
                             }
                         }
                         error++;
                         ex.LogEx(string.Format("{0} {1} {2}", JobKey, "PictureProcess", picture.TransferPictureId));
                     }
                 }
                 if (error == 0)
                 {
                     goodsTransferJobService.PictrueCdnSuccessd(goodsId);
                     goodsTransferJobService.Publish(goodsId);
                 }
                 else
                 {
                     goodsTransferJobService.PictrueCdnFailed(goodsId, errmsg);
                 }
                 goodsId = JobQueue.GoodsTransferJobPictureProcessQueue.GetItem(goodsTransferJobService.PictrueCdning);
             }
         }
     }
 }