Guest User

Untitled

a guest
Mar 18th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. void UpdateWithSrhr4229()
  2. {
  3.     var xl = OfficeHelper.GetExistingExcelInstance();
  4.     var workbooks = xl.Workbooks.Cast<Workbook>();
  5.    
  6.     var recognizationSource = workbooks.Single(x => x.Keywords.Contains("Recognization"));
  7.     var recognization = new RecognizationContext(recognizationSource);
  8.    
  9.     //i have lines like these, when i could have directly used recognization.Employees.DoStuffs(....)
  10.     var employees = recognization.Employees as EntityList<Employee>;
  11.     var locations = recognization.Locations as EntityList<Location>;
  12.     var managers = recognization.Managers as EntityList<Manager>;
  13.     var persons = recognization.Persons as EntityList<Person>;
  14.    
  15.     var srhrSource = workbooks.First(x => x.Name == "Copie de 2015-02-20-14-39-26_Rapp_SRHR4229.xls");
  16.     var srhr = new SrhrContext(srhrSource);
  17.     var srhr4229 = srhr.SRHR4229 as EntityList<SRHR4229>;
  18.     var snapshot = srhr4229.GetTable();
  19.    
  20.     //sanityCheck
  21.     IntegrityCheck(employees.GetTable(), e => e.ManagerID, managers.GetTable(), m => m.ID, "Employee::ManagerID ⊂ Manager:ManagerID");
  22.     IntegrityCheck(employees.GetTable(), e => e.LocationID, locations.GetTable(), l => l.ID, "Employee::LocationID ⊂ Location:LocationID");
  23.     IntegrityCheck(managers.GetTable(), m => m.LocationID, locations.GetTable(), l => l.ID, "Manager::LocationID ⊂ Location:LocationID");
  24.     IntegrityCheck(employees.GetTable(), e => e.ID, persons.GetTable(), p => p.ID, "Employee::ID ⊂ Person:ID");
  25.     IntegrityCheck(managers.GetTable(), m => m.ID, persons.GetTable(), p => p.ID, "Manager::ID ⊂ Person:ID");
  26.  
  27.     employees.GetTable().Select(e => new { Employee = e, Srhr = snapshot.FirstOrDefault (x => x.Matricule == e.ID) })
  28.         .Where(x => x.Srhr != null)
  29.         .Where(x => x.Employee.LocationID != AddressUtility.FormatLocationID(x.Srhr.Code_Postal, x.Srhr.Compl_Add))
  30.         .Select(x => new { x.Employee, LocationID = AddressUtility.FormatLocationID(x.Srhr.Code_Postal, x.Srhr.Compl_Add) })
  31.         //.Select(x => new { x.Employee.ID, x.Employee.LocationID, NewLocationID = x.LocationID, }).Dump();
  32.         .ToObservable().Do(x =>
  33.         {
  34.             var employee = x.Employee;
  35.             employee.LocationID = x.LocationID;
  36.             employees.Update(employee);
  37.         }).DumpLatest("Updating Employee LocationID...");
Advertisement
Add Comment
Please, Sign In to add comment