Exemple #1
0
        public async Task <ActionResult> Index(SearchStudentsModel search, string method, int page = 1)
        {
            // Return all Students
            // If not a post-back (i.e. initial load) set the searchModel to session
            if (Request.Form.Count <= 0)
            {
                if (search.IsEmpty() && Session["SearchStudentsModel"] != null)
                {
                    search = (SearchStudentsModel)Session["SearchStudentsModel"];
                }
            }

            var helper = new StudentHelper();

            var model = helper.GetStudentList(search, search.ParsePage(page));

            Session["SearchStudentsModel"] = search;

            if (method == "Event")
            {
                if (model.Students.Count() <= 0)
                {
                    ShowError("Unfortunately, No students found to generate Event For");
                    return(RedirectToAction("Index"));
                }

                var eventModel = new EventViewModel()
                {
                    //Data = model.Students.Where(m => !m.NoParents).Select(m => m.StudentId).ToArray()
                    Students = model.Students.ToList().Where(m => !m.NoParents).ToList()
                };

                return(await CreateEvent(eventModel));
            }

            if (method == "Report")
            {
                if (model.Students.Count() <= 0)
                {
                    ShowError("Unfortunately, No pupils found to generate Report From");
                    return(RedirectToAction("Index"));
                }

                var reportModel = new ReportModel()
                {
                    Students = model.Records.ToList()
                };

                return(CreatePDF(reportModel));
            }

            ParseSearchDefaults(search);

            return(View(model));
        }
Exemple #2
0
 private void ParseSearchDefaults(SearchStudentsModel model)
 {
     model.Terms       = context.Terms.ToList().OrderByDescending(m => m.StartDate).ToList();
     model.ClassLevels = context.ClassLevels.ToList().OrderBy(x => x.SchoolLevel).ThenBy(o => o.Level);
 }
        public StudentListViewModel GetStudentList(SearchStudentsModel searchModel, int page = 1)
        {
            int pageSize = 20;

            if (page < 1)
            {
                page = 1;
            }

            IEnumerable <Student> records = db.Students.ToList();

            // Remove any default information
            //searchModel.ParseRouteInfo();

            if (!String.IsNullOrEmpty(searchModel.Name))
            {
                string name = searchModel.Name.ToLower();
                records = records.Where(x => x.FirstName.ToLower().Contains(name) || x.LastName.ToLower().Contains(name) || x.FullName.ToLower().Contains(name));
            }

            if (!String.IsNullOrEmpty(searchModel.ParentName))
            {
                string parentName = searchModel.ParentName.ToLower();
                records = records.SelectMany(x => x.Parents).Where(y => y.Parent.Matches(parentName)).Select(m => m.Student);
            }

            if (searchModel.ClassLevel.HasValue)
            {
                records = records.Where(x => x.CurrentLevel.ClassLevelId == searchModel.ClassLevel);
            }

            if (searchModel.Term.HasValue)
            {
                var term = db.Terms.Find(searchModel.Term);
                records = records.Where(x => x.GetTermPayments(term) > 0);
            }

            if (searchModel.Gender.HasValue)
            {
                records = records.Where(x => x.Gender == searchModel.Gender.Value);
            }

            if (searchModel.StudyMode.HasValue)
            {
                records = records.Where(x => x.CurrentLevel.StudyMode == searchModel.StudyMode.Value);
            }

            if (searchModel.NoParents)
            {
                records = records.Where(x => x.NoParents);
            }

            // return after migration, life will be better
            if (!String.IsNullOrEmpty(searchModel.Status))
            {
                records = records.Where(x => x.GetStatus() == searchModel.Status);
            }

            if (searchModel.Stream.HasValue)
            {
                records = records.Where(x => x.Stream == searchModel.Stream);
            }

            // get only that havent been deleted
            if (searchModel.Status != "Terminated")
            {
                records = records.Where(x => !x.Terminated.HasValue);
            }

            var totalPaid        = records.Sum(x => x.Payments.Sum(m => m.Amount));
            var totalBalance     = records.Sum(x => x.OldDebt);
            var termTotalBalance = records.Sum(x => x.Outstanding);
            var termTotalPaid    = records.Sum(x => x.CurrentTermPayments.Sum(m => m.Amount));


            return(new StudentListViewModel
            {
                Students = records
                           .OrderBy(o => o.FullName)
                           .Skip((page - 1) * pageSize)
                           .Take(pageSize),
                TotalPaid = totalPaid,
                TotalBalance = totalBalance,
                TermTotalBalance = termTotalBalance,
                TermTotalPaid = termTotalPaid,
                SearchModel = searchModel,
                Records = records,
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    PageSize = pageSize,
                    TotalItems = records.Count()
                }
            });
        }