public ExamDataVM ListExamData(string centerid) { var sheet = repoOnSite.ListExamData(centerid).Where(x => string.IsNullOrEmpty(x.TestRegisID)); var testRegis = repoOnSite.ListTestRegis(centerid); var group = from item in sheet group item by new { item.Subject.SubjectCode, item.Subject.SubjectName, item.Subject.ContentLanguage, item.Subject.Version, //iten.Subject.Voices, TODO : Groupby Voice } into gitem let qty = gitem.Count() let book = testRegis.Where(x => x.SubjectCode == gitem.Key.SubjectCode && x.ExamLanguage == gitem.Key.ContentLanguage).Count() select new ExamSheetOnSiteRespone { SubjectCode = gitem.Key.SubjectCode, SubjectName = gitem.Key.SubjectName, ExamLanguage = gitem.Key.ContentLanguage, Version = gitem.Key.Version, Quantity = qty, Book = book, VoiceLanguage = "th", //TODO : Groupby Voice IsExamEnough = qty >= book }; var result = new ExamDataVM { ExamSheets = group.ToList(), }; return(result); }