Exemple #1
0
        public async Task <IActionResult> Create([Bind("ID,SeriesName,Author,Creationdate")] StorySeries storySeries)
        {
            if (ModelState.IsValid)
            {
                storySeries.ID = Guid.NewGuid();
                _context.Add(storySeries);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(storySeries));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                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 _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

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

                    if (Input.type == "creator")
                    {
                        Creator creator = new Creator()
                        {
                            ID           = Guid.NewGuid(),
                            UserID       = Guid.Parse(user.Id),
                            CreationTime = DateTime.Now
                        };
                        _context.Creator.Add(creator);
                        await _context.SaveChangesAsync();
                    }

                    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());
        }