public async Task <IActionResult> Create(ReservApprenantViewModel viewModel, Apprenant apprenant) { Reservation resarvation = new Reservation() { Date = viewModel.Date, //Status = viewModel.Status, Cause = viewModel.Cause }; var usId = User.FindFirstValue(ClaimTypes.NameIdentifier); var type = _db.TypeReservations.Single(t => t.Id == viewModel.TypeReservationId); resarvation.ApprenantId = usId; resarvation.TypeReservation = type; _db.Reservations.Add(resarvation); await _db.SaveChangesAsync(); ViewData["type"] = new SelectList(_db.TypeReservations, "Id", "Name", viewModel.TypeReservationId); if (User.IsInRole("admin")) { return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(History))); }
public async Task <IActionResult> Edit(string id, Apprenant apprenant) { if (id != apprenant.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _db.Update(apprenant); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApprenantExists(apprenant.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(apprenant)); }
private void apprenantToolStripMenuItem_Click(object sender, EventArgs e) { Apprenant apprenant = new Apprenant(); apprenant.Show(); this.Hide(); }
public async Task <IActionResult> Create(Apprenant apprenant) { if (ModelState.IsValid) { _db.Add(apprenant); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(apprenant)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new Apprenant { UserName = Input.UserName, 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); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, 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 _userManager.AddToRoleAsync(user, "apprenant"); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl })); } else { 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()); }