public async Task <IActionResult> PutPlateTimeRestaurantGoer([FromRoute] int id, [FromBody] PlateTimeRestaurantGoer plateTimeRestaurantGoer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != plateTimeRestaurantGoer.Id) { return(BadRequest()); } _context.Entry(plateTimeRestaurantGoer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlateTimeRestaurantGoerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
//public void OnGet(string returnUrl = null) //{ // ViewData["SiteKey"] = _configuration["Recaptcha:SiteKey"]; // ReturnUrl = returnUrl; //} //[ValidateRecaptcha] 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."); // creates a new restraunt or restraunt goer associated with the new user and adds role UserRoleAccountRepo userRoleRepo = new UserRoleAccountRepo(_context, _serviceProvider); var usertype = Input.Usertype; var userid = user.Id; var email = user.Email; if (usertype == "Member") { await userRoleRepo.AddUserRole(email, "Member"); RestaurantGoer restaurantgoer = new RestaurantGoer() { UserId = userid, User = _context.AspNetUsers.Where(u => u.Id == userid) .FirstOrDefault() }; await _context.AddAsync(restaurantgoer); await _context.SaveChangesAsync(); } if (usertype == "Manager") { await userRoleRepo.AddUserRole(email, "Manager"); Restaurant restaurant = new Restaurant() { UserId = userid, User = _context.AspNetUsers.Where(u => u.Id == userid) .FirstOrDefault() }; await _context.AddAsync(restaurant); await _context.SaveChangesAsync(); } 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); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // Reset the site key if there is an error. // ViewData["SiteKey"] = _configuration["Recaptcha:SiteKey"]; // If we got this far, something failed, redisplay form return(Page()); }
public async Task UpdateEntry(PlateTime pt) { db.Update(pt); await db.SaveChangesAsync(); }