Esempio n. 1
0
        public ActionResult Create(ParentRegisterModel modelParent)
        {
            var parentModel = Mapper.Map <ParentRegisterModel, Parent>(modelParent);
            var myParent    = _parentRepository.GenerateParentFromRegisterModel(parentModel);

            if (_parentRepository.ExistIdNumber(modelParent.IdNumber))
            {
                _viewMessageLogic.SetNewMessage("Dato Invalido", "Ya existe el numero de Identidad ya existe", ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index"));
            }
            if (_parentRepository.ExistEmail(modelParent.Email))
            {
                _viewMessageLogic.SetNewMessage("Dato Invalido", "El Correo Electronico ya esta en uso", ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index"));
            }
            var newUser = new User
            {
                DisplayName = myParent.FirstName,
                Email       = modelParent.Email,
                Password    = modelParent.Password,
                IsActive    = true,
                Role        = Roles.Padre
            };

            newUser         = _userRepository.Create(newUser);
            myParent.MyUser = newUser;
            _parentRepository.Create(myParent);
            const string title   = "Padre o Tutor Agregado";
            var          content = "El Padre o Tutor " + myParent.FullName + " ha sido agregado exitosamente.";

            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index"));
        }
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);
            }
        }