Exemplo n.º 1
0
 public object DeleteById(int Id)
 {
     try
     {
         EFHelper <PicInfo> eFHelper = new EFHelper <PicInfo>();
         int count = eFHelper.DelBy(p => p.Id == Id);
         return(new NewErrorModel()
         {
             count = count,
             error = new Error(0, "删除成功!", "")
             {
             },
         });
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public NewErrorModel Del(int Id, string ApplyManId)
 {
     try
     {
         using (DDContext context = new DDContext())
         {
             if (context.Roles.Where(r => r.RoleName == "合同管理员" && r.UserId == ApplyManId).ToList().Count > 0)
             {
                 EFHelper <Contract> eFHelper = new EFHelper <Contract>();
                 Expression <Func <Contract, bool> > expression = c => c.Id == Id;
                 eFHelper.DelBy(expression);
                 return(new NewErrorModel()
                 {
                     error = new Error(0, "删除成功!", "")
                     {
                     },
                 });
             }
             else
             {
                 return(new NewErrorModel()
                 {
                     error = new Error(1, "用户没有权限!", "")
                     {
                     },
                 });
             }
         }
     }
     catch (Exception ex)
     {
         return(new NewErrorModel()
         {
             error = new Error(2, ex.Message, "")
             {
             },
         });
     }
 }
 public object SynchroData(int State)
 {
     try
     {
         Stopwatch watch = new Stopwatch();
         watch.Start();
         int count = 0;
         if (State == 0)
         {
             using (KisLocalContext kisLocalContext = new KisLocalContext())
             {
                 using (DDContext DDcontext = new DDContext())
                 {
                     List <DingTalk.Models.KisLocalModels.t_ICItem> t_ICItemList    = kisLocalContext.t_ICItem.ToList();
                     List <DingTalk.Models.DingModels.KisPurchase>  KisPurchaseList = new List <KisPurchase>();
                     //清理旧数据
                     EFHelper <DingTalk.Models.DingModels.KisPurchase> eFHelper = new EFHelper <KisPurchase>();
                     eFHelper.DelBy(k => k.FItemID != null);
                     //构造数据
                     foreach (var item in t_ICItemList)
                     {
                         KisPurchaseList.Add(new KisPurchase()
                         {
                             FNumber = item.FNumber,
                             FItemID = item.FItemID.ToString(),
                             FNote   = item.FNote,
                             FModel  = item.FModel,
                             FName   = item.FName
                         });
                     }
                     //批量插入
                     DDcontext.BulkInsert(KisPurchaseList);
                     DDcontext.BulkSaveChanges();
                     count = t_ICItemList.Count();
                 }
             }
             watch.Stop();
             return(new NewErrorModel()
             {
                 count = count,
                 data = "耗时:" + watch.ElapsedMilliseconds,
                 error = new Error(0, "同步成功!", "")
                 {
                 },
             });
         }
         else
         {
             using (OfficeLocalContext officeLocalContext = new OfficeLocalContext())
             {
                 using (DDContext DDcontext = new DDContext())
                 {
                     List <DingTalk.Models.OfficeLocalModels.t_ICItem> t_ICItemList  = officeLocalContext.t_ICItem.ToList();
                     List <DingTalk.Models.DingModels.KisOffice>       KisOfficeList = new List <KisOffice>();
                     //清理旧数据
                     EFHelper <DingTalk.Models.DingModels.KisOffice> eFHelper = new EFHelper <KisOffice>();
                     eFHelper.DelBy(k => k.FItemID != null);
                     //构造数据
                     foreach (var item in t_ICItemList)
                     {
                         KisOfficeList.Add(new KisOffice()
                         {
                             FNumber = item.FNumber,
                             FItemID = item.FItemID.ToString(),
                             FNote   = item.FNote,
                             FModel  = item.FModel,
                             FName   = item.FName
                         });
                     }
                     //批量插入
                     DDcontext.BulkInsert(KisOfficeList);
                     DDcontext.BulkSaveChanges();
                     count = t_ICItemList.Count();
                 }
             }
             watch.Stop();
             return(new NewErrorModel()
             {
                 count = count,
                 data = "耗时:" + watch.ElapsedMilliseconds,
                 error = new Error(0, "同步成功!", "")
                 {
                 },
             });
         }
     }
     catch (Exception ex)
     {
         return(new NewErrorModel()
         {
             error = new Error(1, ex.Message, "")
             {
             },
         });
     }
 }