Esempio n. 1
0
        public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            _viewMessageLogic.SetViewMessageIfExist();
            var allParents = _parentRepository.GetAllParents();

            ViewBag.CurrentSort      = sortOrder;
            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.IdNumberSortParm = sortOrder == "IdNumber" ? "idNumber_desc" : "IdNumber";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            if (!string.IsNullOrEmpty(searchString))
            {
                allParents = _parentRepository.Filter(x => x.FullName.Contains(searchString)).ToList();
            }
            var allParentDisplaysModel = allParents.Select(Mapper.Map <Parent, DisplayParentModel>).ToList();

            ViewBag.CurrentFilter = searchString;
            switch (sortOrder)
            {
            case "name_desc":
                allParentDisplaysModel = allParentDisplaysModel.OrderByDescending(s => s.FullName).ToList();
                break;

            case "IdNumber":
                allParentDisplaysModel = allParentDisplaysModel.OrderBy(s => s.IdNumber).ToList();
                break;

            case "idNumber_desc":
                allParentDisplaysModel = allParentDisplaysModel.OrderByDescending(s => s.IdNumber).ToList();
                break;

            default:      // Name ascending
                allParentDisplaysModel = allParentDisplaysModel.OrderBy(s => s.FullName).ToList();
                break;
            }
            const int pageSize   = 10;
            var       pageNumber = (page ?? 1);

            return(View(allParentDisplaysModel.ToPagedList(pageNumber, pageSize)));
        }
Esempio n. 2
0
        private void SaveData(IEnumerable <Student> listStudents, IEnumerable <Parent> listParents, AcademicYear academicYear, List <string> emails)
        {
            var allEnrolls = _enrollRepository.GetAllsEnrolls();
            var enrls      = allEnrolls.Where(x => x.AcademicYear.Id == academicYear.Id);

            if (enrls.Any())
            {
                throw new Exception("Ya hay alumos en este grado, borrelos e ingreselos denuevo");
            }

            var allParents  = _parentRepository.GetAllParents();
            var allStudents = _studentRepository.GetAllStudents();

            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((ParentRepository)_parentRepository).GeContext())))
            {
                return;
            }
            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((StudentRepository)_studentRepository).GeContext())))
            {
                return;
            }
            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((AcademicYearRepository)_academicYearRepository).GeContext())))
            {
                return;
            }
            int iterator = 0;

            foreach (var pare in listParents)
            {
                var temp = allParents.Where(x => x.IdNumber == pare.IdNumber);
                if (!temp.Any())
                {
                    var newUser = new User
                    {
                        DisplayName = pare.FirstName,
                        Email       = emails[iterator],
                        Password    = _passwordGenerationService.GenerateTemporaryPassword(),
                        IsActive    = true,
                        Role        = Roles.Padre
                    };
                    //TODO: add to newUsers table.
                    newUser = _userRepository.Create(newUser);

                    pare.MyUser = newUser;
                    _parentRepository.Create(pare);
                }
                else
                {
                    pare.Id = temp.First().Id;
                }
                iterator++;
            }
            foreach (var stu in listStudents)
            {
                var temp = allStudents.Where(x => x.IdNumber == stu.IdNumber);
                if (!temp.Any())
                {
                    stu.MyUser = stu.Tutor1.MyUser;
                    _studentRepository.Create(stu);
                }
                else
                {
                    stu.Id = temp.First().Id;
                }
                var enr = allEnrolls.Where(x => x.AcademicYear.Id == academicYear.Id && x.Student.Id == stu.Id);
                if (enr.Any())
                {
                    continue;
                }
                var te = new Enroll();
                var academicYearTemp = _academicYearRepository.GetById(academicYear.Id);
                var studentTemp      = _studentRepository.GetById(stu.Id);
                te.AcademicYear = academicYearTemp;
                te.Student      = studentTemp;
                _enrollRepository.Create(te);
            }
        }