Ejemplo n.º 1
0
        public IEnumerable <FeesForAllStudentsByClass> GetFeesForAllStudentsByClass()
        {
            List <FeesForAllStudentsByClass> feesForAllStudentsByClass = new List <FeesForAllStudentsByClass>();

            var allStudents       = _sharedService.GetAllStudents();
            var allClasses        = _sharedService.GetAllClass();
            var allStudentClasses = _sharedService.GetAllStudentClass();
            var allFeeTerms       = _sharedService.GetAllFeeTerms();
            var allFees           = _sharedService.GetAllFees();

            // Need ClassName, NoOfStudents, TotalFee, TotalFeePaid, TotalFeeBalance

            // Per class hw many students.
            var studentsPerClass = allStudentClasses.Where(x => x.IsActive).GroupBy(x => x.ClassId)
                                   .OrderBy(x => x.Key);

            if (studentsPerClass != null && studentsPerClass.Any())
            {
                foreach (var item in studentsPerClass)
                {
                    FeesForAllStudentsByClass itemToAdd = new FeesForAllStudentsByClass();
                    var currentClass = allClasses.First(x => x.Id == item.Key);
                    itemToAdd.ClassName    = currentClass.Name;
                    itemToAdd.NoOfStudents = item.Count();
                    itemToAdd.TotalFee     = item.Sum(x => x.FeeAgreed);
                    var studentClassIdSet = item.Select(x => x.Id);
                    itemToAdd.TotalFeePaid    = allFees.Where(x => studentClassIdSet.Contains(x.StudentClassId)).Sum(x => x.FeePaid);
                    itemToAdd.TotalFeeBalance = itemToAdd.TotalFee - itemToAdd.TotalFeePaid;
                    feesForAllStudentsByClass.Add(itemToAdd);
                }
            }
            return(feesForAllStudentsByClass);
        }