Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var tmpRes = query.List<object[]>().Select(a => new {
  2. EmployeeId = a[0].ToInt32(),
  3. StudiesModeId = a[1].ToInt32Nullable(),
  4. FormId = a[2].ToInt32Nullable()
  5. }).ToArray();
  6.  
  7. if (tmpRes != null && tmpRes.Count() > 0)
  8. {
  9. var tmpGroupedRes = tmpRes.GroupBy(a => a.EmployeeId);
  10. //all types or forms for each employee must have value or all of them must not have it - otherwise we throw an exception
  11. if (!tmpGroupedRes.Any(a => a.All(b => b.StudiesModeId.HasValue || b.FormId.HasValue) || a.All(b => !b.StudiesModeId.HasValue && !b.FormId.HasValue)))
  12. throw new Exception("Niespójne dane w pensum pracownika! Opcja 'tylko suma' nie daje możliwości wpisania godzin z podziałem na formy.");
  13. result = tmpGroupedRes.Select(a => new { PracId = a.Key, TylkoSuma = !a.All(b => b.StudiesModeId.HasValue || b.FormId.HasValue) })
  14. .ToDictionary(a => a.PracId, a => a.TylkoSuma);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement