using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
public static void Main()
List<Parent> ParentList = new List<Parent>(){
new Parent{Id = 0, Date = new DateTime(2021, 1, 1),
Children = new List<Child>{
new Child{Id = 1, ParentId = 0, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 2, ParentId = 0, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 10, 22, 33) },
new Child{Id = 3, ParentId = 0, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 1, Date = new DateTime(2021, 1, 2, 11, 22, 33),
Children = new List<Child>{
new Child{Id = 4, ParentId = 1, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 5, ParentId = 1, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 2, Date = new DateTime(2021, 1, 3, 11, 48, 44),
Children = new List<Child>{
new Child{Id = 6, ParentId = 2, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 10, 22, 33) },
new Child{Id = 7, ParentId = 2, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 3, Date = new DateTime(2021, 1, 4, 15, 2, 10),
Children = new List<Child>{
new Child{Id = 8, ParentId = 3, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 9, ParentId = 3, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 10, 22, 33) },
new Child{Id = 10, ParentId = 3, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 4, Date = new DateTime(2021, 1, 5, 8, 22, 33),
Children = new List<Child>{
new Child{Id = 11, ParentId = 4, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 12, ParentId = 4, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 5, Date = new DateTime(2021, 1, 6, 9, 48, 44),
Children = new List<Child>{
new Child{Id = 13, ParentId = 5, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 14, ParentId = 5, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) },
new Child{Id = 15, ParentId = 5, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 6, Date = new DateTime(2021, 1, 7, 9, 48, 45),
Children = new List<Child>{
new Child{Id = 16, ParentId = 6, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 17, ParentId = 6, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 7, Date = new DateTime(2021, 1, 8, 8, 12, 51),
Children = new List<Child>{
new Child{Id = 18, ParentId = 7, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 19, ParentId = 7, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 8, Date = new DateTime(2021, 1, 9, 8, 14, 38),
Children = new List<Child>{
new Child{Id = 20, ParentId = 8, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 9, Date = new DateTime(2021, 1, 10, 7, 22, 24),
Children = new List<Child>{
new Child{Id = 21, ParentId = 9, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Parent{Id = 10, Date = new DateTime(2021, 1, 11, 7, 22, 24),
Children = new List<Child>{
new Child{Id = 22, ParentId = 10, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 23, ParentId = 10, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 10, 22, 33) },
new Child{Id = 24, ParentId = 10, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
new Parent{Id = 11, Date = new DateTime(2021, 1, 12, 7, 22, 24),
Children = new List<Child>{
new Child{Id = 25, ParentId = 11, KeyName = "CheckIn", Date = new DateTime(2021, 9, 1, 9, 22, 33) },
new Child{Id = 26, ParentId = 11, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 10, 22, 33) },
new Child{Id = 27, ParentId = 11, KeyName = "CheckOut", Date = new DateTime(2021, 9, 1, 19, 22, 33) }
DateTime FirstDate = new DateTime(2021, 1, 1, 0, 0, 0);
DateTime SecondDate = new DateTime(2021, 1, 12, 23, 59, 59);
var result = ParentList.Where(cd => cd.Date >= FirstDate && cd.Date <= SecondDate && cd.Children.GroupBy(ch => ch.KeyName).Where(ch => ch.Count() > 1).ToList().Count >= 1 )
List<Employee> Employees = new List<Employee>(){new Employee{Id = 1, Name = "Mouhamed Saleem AlZayat", Number = "1807"}};
WrongPunchServiceModel reportModel = new WrongPunchServiceModel();
reportModel.WorngPunchEmployeeServiceModel = Employees.Select(e => new WorngPunchEmployeeServiceModel
WrongPunchDayServiceModel = result.Select(cm => new WrongPunchDayServiceModel {
WrongPunchDayDetailsServiceModel =
cm.Children.Select(cdd => new WrongPunchDayDetailsServiceModel {
foreach(WorngPunchEmployeeServiceModel t in reportModel.WorngPunchEmployeeServiceModel){
Console.WriteLine(t.ToString());
foreach(WrongPunchDayServiceModel wpd in t.WrongPunchDayServiceModel){
Console.WriteLine($" ---> {wpd.ToString()}");
foreach(WrongPunchDayDetailsServiceModel wpdd in wpd.WrongPunchDayDetailsServiceModel){
Console.WriteLine($" ---> ---> {wpdd.ToString()}");
public DateTime Date{get; set;}
public override string ToString(){
return $"Id: {Id.ToString()} Date: " + Date.ToString("MM/dd/yyyy HH:mm:ss");
public double? Value{get;set;}
public List<Child> Children{get;set;} = new List<Child> ();
public DateTime Date{get; set;}
public string KeyName {get;set;}
public int ParentId {get; set;}
public override string ToString(){
return $"Id: {Id.ToString()}, Date: " + Date.ToString("MM/dd/yyyy HH:mm:ss") + $", ParentId: {ParentId}";
public string Name {get;set;}
public string Number {get;set;}
public class WrongPunchServiceModel
public DateTime StartDate { get; set; }
public Nullable<DateTime> EndDate { get; set; }
public int StartYear { get; set; }
public int EndYear { get; set; }
public int StartMonth { get; set; }
public string StartMonthName { get; set; }
public int EndMonth { get; set; }
public string EndMonthName { get; set; }
public List<WorngPunchEmployeeServiceModel> WorngPunchEmployeeServiceModel { get; set; }
public class WorngPunchEmployeeServiceModel
public string Number { get; set; }
public string Name { get; set; }
public int EmployeeId { get; set; }
public List<WrongPunchDayServiceModel> WrongPunchDayServiceModel { get; set; }
public override string ToString(){
return $"WPE: Employee Id: {EmployeeId.ToString()} Name: {Name}" ;
public class WrongPunchDayServiceModel
public DateTime Date{ get; set; }
public List<WrongPunchDayDetailsServiceModel> WrongPunchDayDetailsServiceModel { get; set; }
public override string ToString(){
return $"WPD: Date: " + Date.ToString("MM/dd/yyyy") + $", WPDD Count:{WrongPunchDayDetailsServiceModel.Count}";
public class WrongPunchDayDetailsServiceModel
public DateTime PunchTime { get; set; }
public int PunchId { get; set; }
public string PunchType{ get; set; }
public override string ToString(){
return $"WPDD: Punch Id: {PunchId}, Punch Type: {PunchType}, Punch Time: " + PunchTime.ToString("MM/dd/yyyy HH:mm:ss");