public static Student RowToStudent(IEnumerable <DataRow> rows, Student.Includes include) { DataRow row = rows.FirstOrDefault(); BranchesStudents branchesStudent = new BranchesStudents(); if (include.HasFlag(Student.Includes.BranchStudent)) { var studentInstoitutionList = rows.GroupBy(studentRow => DataRowHelper.GetValue <int>(studentRow, Tables.BranchStudents.Id.FullName), (id, group) => BranchStudentConverter.RowToBranchStudent(group.CopyToDataTable().AsEnumerable(), Student.Includes.Branch)).ToList(); branchesStudent.AddRange(studentInstoitutionList); } return(new Student() { FirstName = DataRowHelper.GetValue <string>(row, Tables.Students.FirstName.FullName), LastName = DataRowHelper.GetValue <string>(row, Tables.Students.LastName.FullName), AccountNumber = DataRowHelper.GetValue <string>(row, Tables.Students.AccountNumber.FullName), Bank = include.HasFlag(Student.Includes.Bank) ? BankConverter.RowToBank(row) : null, Address = include.HasFlag(Student.Includes.Address) ? AddressConverter.RowToAddress(row) : null, BornDate = DataRowHelper.GetValue <DateTime>(row, Tables.Students.BornDate.FullName), PhoneNumber = DataRowHelper.GetValue <string>(row, Tables.Students.PhoneNumber.FullName), CellphoneNumber = DataRowHelper.GetValue <string>(row, Tables.Students.CellphoneNumber.FullName), ChildrenNumber = DataRowHelper.GetValue <int>(row, Tables.Students.ChildrenNumber.FullName), FaxNumber = DataRowHelper.GetValue <string>(row, Tables.Students.FaxNumber.FullName), IdCard = DataRowHelper.GetValue <string>(row, Tables.Students.IdCard.FullName), IdentityNumber = DataRowHelper.GetValue <string>(row, Tables.Students.IdentityNumber.FullName), Image = DataRowHelper.GetValue <string>(row, Tables.Students.Image.FullName), JobWife = DataRowHelper.GetValue <string>(row, Tables.Students.JobWife.FullName), MarriedChildrenNumber = DataRowHelper.GetValue <int>(row, Tables.Students.MarriedChildrenNumber.FullName), MonthlyIncome = DataRowHelper.GetValue <decimal>(row, Tables.Students.MonthlyIncome.FullName), Id = DataRowHelper.GetValue <int>(row, Tables.Students.Id.FullName), TravelExpenses = DataRowHelper.GetValue <decimal>(row, Tables.Students.TravelExpenses.FullName), WifeName = DataRowHelper.GetValue <string>(row, Tables.Students.WifeName.FullName), StudentChildren = include.HasFlag(Student.Includes.Children) ? rows.GroupBy(studentRow => DataRowHelper.GetValue <int>(studentRow, Tables.StudentsChildren.Id.FullName), (id, child) => StudentChildrenConverter.RowToStudentChildren(child.CopyToDataTable().AsEnumerable())).ToList() : null, StudentBranches = include.HasFlag(Student.Includes.BranchStudent) ? branchesStudent : null, IsActive = DataRowHelper.GetValue <bool>(row, Tables.Students.IsActive.FullName) }); }
//in the middle public static Branch RowToBranch(IEnumerable <DataRow> rows, Branch.Includes includes) { DataRow row = rows.FirstOrDefault(); return(new Branch() { Id = DataRowHelper.GetValue <int>(row, Tables.Branches.Id.FullName), Address = includes.HasFlag(Branch.Includes.Address)?AddressConverter.RowToAddress(row):null, Head = includes.HasFlag(Branch.Includes.UserExtraDetails) ? UserExtraDetailsConverter.RowToUserExtraDetails(row) : null, Image = DataRowHelper.GetValue <string>(row, Tables.Branches.Image.FullName), IsActive = DataRowHelper.GetValue <bool>(row, Tables.Branches.IsActive.FullName), Name = DataRowHelper.GetValue <string>(row, Tables.Branches.Name.FullName), OpeningDate = DataRowHelper.GetValue <DateTime>(row, Tables.Branches.OpeningDate.FullName), StudentsNumber = DataRowHelper.GetValue <int>(row, Tables.Branches.StudentsNumber.FullName), Type = includes.HasFlag(Branch.Includes.BranchType)?BranchTypeConverter.RowToBranchType(row):null, StudySubjects = DataRowHelper.GetValue <string>(row, Tables.Branches.StudySubjects.FullName), ExamRules = includes.HasFlag(Branch.Includes.Rules)?BranchRulesConverter.RowToExamRules(row):null, AttendanceRules = includes.HasFlag(Branch.Includes.Rules) ? BranchRulesConverter.RowToAttendanceRules(row) : null, ActivityHours = includes.HasFlag(Branch.Includes.ActivityHours) ? rows.GroupBy(branchRow => DataRowHelper.GetValue <int>(branchRow, Tables.BranchActivityHours.Id.FullName), (id, hour) => BranchActivityHoursConverter.RowToBranchActivityHours(hour.CopyToDataTable().AsEnumerable())).ToList() : null, Institution = includes.HasFlag(Branch.Includes.Institution)?InstitutionConverter.RowToInstitution(row):null }); }