List<CashflowComparer> FormHashesList(List<tbl_Cashflow> listTs, List<Transfer> list1C, DateTime compareDate, Entities db)
 {
     List<CashflowComparer> hashes = new List<CashflowComparer>();
     foreach (tbl_Cashflow t in listTs)
     {
         string h = CashflowComparer.getHash(t);
         CashflowComparer cc = new CashflowComparer()
         {
             hash = h,
             objTs = t
         };
         hashes.Add(cc);
     }
     foreach (Transfer t in list1C)
     {
         tbl_Cashflow c = CreateCashflow(db, t, compareDate);
         string h = CashflowComparer.getHash(c);
         if (hashes.Exists(x => x.hash == h))
         {
             hashes.FirstOrDefault(x => x.hash == h).obj1C = c;
         }
         else
         {
             CashflowComparer cc = new CashflowComparer()
             {
                 hash = h,
                 obj1C = c
             };
             hashes.Add(cc);
         }
     }
     return hashes;
 }
 void GrantToManagerAccessToCashflow(CashflowComparer cc, Entities db)
 {
     if (cc.obj1C.ManagerID.HasValue) 
     {
         if (db.tbl_CashflowRight.Count(x => x.RecordID == cc.obj1C.ID && x.AdminUnitID == cc.obj1C.ManagerID) == 0)
         {
             Guid managerAdminUnitID = db.tbl_AdminUnit.FirstOrDefault(x => x.UserContactID == cc.obj1C.ManagerID).ID;
             tbl_CashflowRight rights = new tbl_CashflowRight
             {
                 AdminUnitID = managerAdminUnitID,
                 CanChangeAccess = 1,
                 CanDelete = 0,
                 CanRead = 1,
                 CanWrite = 1,
                 ID = Guid.NewGuid(),
                 RecordID = cc.obj1C.ID
             };
             db.tbl_CashflowRight.Add(rights);
         }
     }
 }
 void Update1cDocNumIns(Entities db, List<Transfer> list1C, List<tbl_Cashflow> lts, DateTime compareDate)
 {
     List<CashflowComparer> hashes = new List<CashflowComparer>();
     List<tbl_Cashflow> listTs = lts.Where(x => String.IsNullOrEmpty(x.Obj1cDocNumIn)).ToList();
     foreach (tbl_Cashflow c in listTs)
     {
         string h = CashflowComparer.getHashWithoutDocNum(c);
         if (!hashes.Exists(x => x.hash == h))
         {
             CashflowComparer cc = new CashflowComparer()
             {
                 hash = h,
                 objTs = c
             };
             hashes.Add(cc);
         }
     }
     foreach (Transfer t in list1C)
     {
         tbl_Cashflow c = CreateCashflow(db, t, compareDate);
         string h = CashflowComparer.getHashWithoutDocNum(c);
         if (hashes.Exists(x => x.hash == h))
         {
             hashes.FirstOrDefault(x => x.hash == h).obj1C = c;
         }
         else
         {
             CashflowComparer cc = new CashflowComparer()
             {
                 hash = h,
                 obj1C = c
             };
             hashes.Add(cc);
         }
     }
     foreach (CashflowComparer cc in hashes)
     {
         if (cc.Action == ImportAction.UPDATE_1CDOCNUMIN)
         {
             //Console.WriteLine("Update 1C DocNumIn");
             db.tbl_Cashflow.FirstOrDefault(x => x.ID == cc.objTs.ID).Obj1cDocNumIn = cc.obj1C.Obj1cDocNumIn;
         }
     }
     db.SaveChanges();
 }