Exemplo n.º 1
0
        public async Task CreateMarkPhilosophyAsync(decimal mark, PMGUser user)
        {
            Philosophy philosophy = new Philosophy
            {
                Mark = mark,
                Day  = DateTime.UtcNow
            };

            user.Bookmark.PhilosophyMarks.Add(philosophy);
            await context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task CreateMarkEnglishAsync(decimal mark, PMGUser user)
        {
            English english = new English
            {
                Mark = mark,
                Day  = DateTime.UtcNow
            };

            user.Bookmark.EnglishMarks.Add(english);
            await context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task CreateMarkMathematicsAsync(decimal mark, PMGUser user)
        {
            Mathematics math = new Mathematics
            {
                Mark = mark,
                Day  = DateTime.UtcNow
            };

            user.Bookmark.MathematicsMarks.Add(math);
            await context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new PMGUser
                {
                    UserName    = Input.Username,
                    Email       = Input.Email,
                    FirstName   = Input.FirstName,
                    LastName    = Input.LastName,
                    UCN         = Input.UCN,
                    DateOfBirth = Input.DateOfBirth,
                    Role        = Input.Role
                };


                var result = await _userManager.CreateAsync(user, Input.Password);

                if (_userManager.Users.Count() == 1)
                {
                    user.Role = "Admin";
                    await _userManager.AddToRoleAsync(user, "Admin");
                }

                else if (Input.Role == "Teacher")
                {
                    await _userManager.AddToRoleAsync(user, "Teacher");
                }

                else if (Input.Role == "Student")
                {
                    Bookmark bookmark = new Bookmark();
                    user.Bookmark = bookmark;
                    await _userManager.AddToRoleAsync(user, "Student");
                }

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }