public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await usersRepository.OpenConnectionAsync();

                    AppUser user = await usersRepository.GetByEmailAsync(model.Email);

                    if (user != null && usersRepository.VerifyPassword(user, model.Password))
                    {
                        await Authenticate(user);

                        return(RedirectToAction("Index", "Home"));
                    }
                    ModelState.AddModelError("", "Invalid login and/or password");
                }
                finally
                {
                    usersRepository.CloseConnection();
                }
            }
            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> SubmitCourseWork()
        {
            AppUser currentStudent = null;

            try
            {
                await users.OpenConnectionAsync();

                currentStudent = await users.GetByEmailAsync(User.Identity.Name);
            }
            finally
            {
                users.CloseConnection();
            }

            try
            {
                await courseWorks.OpenConnectionAsync();

                CourseWork courseWork = await courseWorks.GetAsync(currentStudent.Id);

                return(View(new CourseWorkSubmissionModel
                {
                    StudentId = currentStudent.Id,
                    Theme = courseWork?.Theme ?? string.Empty,
                    Task = courseWork?.Task ?? string.Empty
                }));
            }
            finally
            {
                courseWorks.CloseConnection();
            }
        }