internal List<FilteredHistoryResponsetoTutor> GetHistoryForTutor(Entity objReq) { using (var db = new WizzDataContext()) { List<FilteredHistoryResponsetoTutor> studentList = new List<FilteredHistoryResponsetoTutor>(); int userId = Convert.ToInt32(objReq.userId); var sessionList = db.usp_GetHistoryForTutor(userId).ToList(); List<usp_GetHistoryForTutorResult> ListSession = new List<usp_GetHistoryForTutorResult>(); if (sessionList == null || sessionList.Count == 0) { return studentList; } foreach (var n in sessionList) { var data = sessionList.Where(x => x.uniqueRequestId == n.uniqueRequestId).ToList(); if (data != null && data.Count > 1) { if (!ListSession.Any(x => x.uniqueRequestId == n.uniqueRequestId)) { var count = sessionList.Where(x => x.uniqueRequestId == n.uniqueRequestId).Sum(x => x.TotalMinutes); var avgRating = sessionList.Where(x => x.uniqueRequestId == n.uniqueRequestId).Average(x => x.tutorRating); data[0].TotalMinutes = count; data[0].tutorRating = avgRating; ListSession.Add(data[0]); } //var countS = sessionList.Where(x => x.uniqueRequestId == n.uniqueRequestId).ToList(); ////var tutorRating = sessionList.Where(x => x.uniqueRequestId == n.uniqueRequestId).Sum(x => x.tutorRating); //int totalMins = 0; //decimal rat = 0; //foreach (var val in countS) //{ // totalMins += Convert.ToInt32(val.TotalMinutes); // rat += Convert.ToDecimal(val.tutorRating); //} //data[0].TotalMinutes = totalMins; //data[0].tutorRating = rat / 3; //if (!ListSession.Any(x => x.uniqueRequestId == n.uniqueRequestId)) // ListSession.Add(data[0]); //sessionList.RemoveAll(x => x.uniqueRequestId == n.uniqueRequestId); } else { if (!ListSession.Any(x => x.uniqueRequestId == n.uniqueRequestId)) ListSession.Add(n); } } foreach (var c in ListSession) { var list = ListSession.Where(s => s.subjectId == c.subjectId).ToList(); if (!studentList.Any(x => x.subjectId == c.subjectId.ToString())) { FilteredHistoryResponsetoTutor FilteredObj = new FilteredHistoryResponsetoTutor(); FilteredObj.subjectId = c.subjectId.ToString(); FilteredObj.subjectType = c.subjectType.ToString(); FilteredObj.subjectName = c.subjectName.ToString(); List<HistoryResponsetoTutor> model = new List<HistoryResponsetoTutor>(); model = (from r in ListSession.Where(x => x.subjectId == c.subjectId) select new HistoryResponsetoTutor { studentId = r.tutorId.ToString(), studentName = r.tutorName, sessionId = r.sessionId.ToString(), tutorRating = Convert.ToString(r.tutorRating), totalHours = r.TotalMinutes.ToString(), profilepic = r.profilePic.ToString(), uniqueRequestId = r.uniqueRequestId.ToString(), }).ToList(); FilteredObj.DetailsList = model; studentList.Add(FilteredObj); } //return studentList; } return studentList; } }