public async Task <IActionResult> Create([Bind("AspId,FirstName,MiddleName,LastName,Email,PhoneNumber,IsViewOnly,AgeRange,Id")] User user) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } var password = "******"; if (ModelState.IsValid) { var identityUser = new IdentityUser { UserName = user.Email, Email = user.Email }; var result = await _userManager.CreateAsync(identityUser, password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = identityUser.Id, code = code }, protocol: Request.Scheme); user.AspId = identityUser.Id; _context.Add(user); await _context.SaveChangesAsync(); await _emailSender.SendEmailAsync(user.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); return(RedirectToAction(nameof(Index))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(user)); }
public async Task <IActionResult> Create([Bind("Name,Value,Id")] Setting setting) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(setting); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(setting)); }
public async Task <IActionResult> Create([Bind("Name,Address,PictureUrl,ContactPhone,MapUrl,Coordinate,Id")] Location location) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(location); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(location)); }
public async Task <IActionResult> Create([Bind("Title,Description,PictureUrl,Capacity,StartDate,EndDate,Amount,HouseKeepingInfo,IsActive,LocationID,ActivityTypeID,Id")] Activity activity) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser?.IsViewOnly ?? true) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(activity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ActivityTypeID"] = new SelectList(_context.ActivityTypes, "Id", "Name", activity.ActivityTypeID); ViewData["LocationID"] = new SelectList(_context.Locations, "Id", "Name", activity.LocationID); return(View(activity)); }