Skip to content

Instantly share code, notes, and snippets.

@ProximaB
Created July 7, 2019 20:36
Show Gist options
  • Save ProximaB/1c25d037c14772a21816e637cab42d6b to your computer and use it in GitHub Desktop.
Save ProximaB/1c25d037c14772a21816e637cab42d6b to your computer and use it in GitHub Desktop.
var tmpRes = query.List<object[]>().Select(a => new {
EmployeeId = a[0].ToInt32(),
StudiesModeId = a[1].ToInt32Nullable(),
FormId = a[2].ToInt32Nullable()
}).ToArray();
if (tmpRes != null && tmpRes.Count() > 0)
{
var tmpGroupedRes = tmpRes.GroupBy(a => a.EmployeeId);
//all types or forms for each employee must have value or all of them must not have it - otherwise we throw an exception
if (!tmpGroupedRes.Any(a => a.All(b => b.StudiesModeId.HasValue || b.FormId.HasValue) || a.All(b => !b.StudiesModeId.HasValue && !b.FormId.HasValue)))
throw new Exception("Niespójne dane w pensum pracownika! Opcja 'tylko suma' nie daje możliwości wpisania godzin z podziałem na formy.");
result = tmpGroupedRes.Select(a => new { PracId = a.Key, TylkoSuma = !a.All(b => b.StudiesModeId.HasValue || b.FormId.HasValue) })
.ToDictionary(a => a.PracId, a => a.TylkoSuma);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment