Exemplo n.º 1
0
        public IActionResult Create()
        {
            var subjects  = this.subjectsServices.GetAll <SubjectsDropDownViewModel>();
            var viewModel = new TeacherCreateInputModel();

            viewModel.Subjects = subjects;
            return(this.View(viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateTeacher()
        {
            var user = await _userManager.GetUserAsync(User);

            var isAdmin = await IsAdmin();

            var schools    = _schoolsServices.GetAllByUserId <SchoolViewModel>(user?.UniqueGradebookId, isAdmin);
            var inputModel = new TeacherCreateInputModel
            {
                Schools = schools.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList()
            };

            return(View(inputModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateAsync(TeacherCreateInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                inputModel.Subjects = this.subjectsServices.GetAll <SubjectsDropDownViewModel>();
                return(this.View(inputModel));
            }

            var teacherId = await this.teacherServises.CreateAsync(inputModel.FirstName, inputModel.LastName, inputModel.SubjectId, inputModel.Email);

            var findUser = await this.userManager.FindByEmailAsync(inputModel.Email);

            if (findUser == null)
            {
                var user = new ApplicationUser
                {
                    UserName       = inputModel.Email,
                    Email          = inputModel.Email,
                    EmailConfirmed = true,
                };

                var password = "******";

                var result = await this.userManager.CreateAsync(user, password);

                if (result.Succeeded)
                {
                    await this.teacherServises.AddUserToTeacher(teacherId, user.Id);

                    await this.userManager.AddToRoleAsync(user, GlobalConstants.TeacherRoleName);

                    return(this.RedirectToAction("Details", new { id = teacherId }));
                }
            }
            else
            {
                var result = await this.userManager.AddToRoleAsync(findUser, GlobalConstants.TeacherRoleName);

                await this.teacherServises.AddUserToTeacher(teacherId, findUser.Id);

                if (result.Succeeded)
                {
                    return(this.RedirectToAction("Details", new { id = teacherId }));
                }
            }

            return(this.RedirectToAction("Details", new { id = teacherId }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateTeacher(TeacherCreateInputModel inputModel)
        {
            if (!ModelState.IsValid || inputModel.Teacher.SchoolId.IsNullOrEmpty())
            {
                //ToDo: in case of null school/class, return appropriate message or add model validation?
                return(View(inputModel));
            }

            try
            {
                var confirmViewModel = await _teachersService.CreateTeacher <ConfirmCreatedViewModel>(inputModel.Teacher);

                return(RedirectToAction(nameof(ConfirmCreated), confirmViewModel));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An exception occured during new teacher record creation. Ex: {e.Message}");
                return(RedirectToAction("Error", "Home"));
            }
        }