public async Task <IActionResult> Edit(long id, [Bind("IdProfesseur,Nom,Prenom,Matericule,Dateembauche,MatiereId,UtilisateurId")] Model.Professeur professeur) { _logger.LogInformation(professeur.UtilisateurId.ToString()); if (id != professeur.IdProfesseur) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(professeur); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProfesseurExists(professeur.IdProfesseur)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(professeur)); }
public async Task <IActionResult> Edit(long id, [Bind("IdAdministrateur,Nom,Prenom,UtilisateurId")] Model.Administrateur Administrateur) { if (id != Administrateur.IdAdministrateur) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(Administrateur); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdministrateurExists(Administrateur.IdAdministrateur)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(Administrateur)); }
public async Task <IActionResult> Create([Bind("Libelle")] Model.Salle Salle) { if (ModelState.IsValid) { _context.Add(Salle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(Salle)); }
public async Task <IActionResult> Create([Bind("Nom,Prenom,Matricule,ClasseIdClasse")] Model.Etudiant etudiant) { if (ModelState.IsValid) { _context.Add(etudiant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(etudiant)); }
public async Task <IActionResult> Create([Bind("Dateseance,Heuredebut,Heurefin,ClasseId,ProfesseurId,SalleId")] Model.Seance Seance) { if (ModelState.IsValid) { _context.Add(Seance); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(Seance)); }
public async Task <IActionResult> OnPostAsync() { this.Matieres = await _db.Matiere.ToListAsync(); if (ModelState.IsValid) { var user = new Utilisateur { UserName = Input.Email, Email = Input.Email, datenaissance = Input.Datenaissance, statut = Input.Statut }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var createduser = await _context.Aspnetusers.Where(s => s.Id == user.Id) .FirstOrDefaultAsync(); if (Input.Statut == "prof") { var professeur = new Model.Professeur { Nom = Input.Nom, Prenom = Input.Prenom, Dateembauche = Input.DateEmbauche, UtilisateurId = createduser.Id, Matericule = Input.Matricule, MatiereId = Input.MatiereId }; _context.Professeur.Add(professeur); await _context.SaveChangesAsync(); if (!await _rolemanager.RoleExistsAsync(RoleManagement.Adminuser)) { await _rolemanager.CreateAsync(new IdentityRole(RoleManagement.Adminuser)); } if (!await _rolemanager.RoleExistsAsync(RoleManagement.Profuser)) { await _rolemanager.CreateAsync(new IdentityRole(RoleManagement.Profuser)); } await _userManager.AddToRoleAsync(user, RoleManagement.Profuser); } else { var administrateur = new Model.Administrateur { Nom = Input.Nom, Prenom = Input.Prenom, UtilisateurId = createduser.Id }; _context.Administrateur.Add(administrateur); await _context.SaveChangesAsync(); if (!await _rolemanager.RoleExistsAsync(RoleManagement.Adminuser)) { await _rolemanager.CreateAsync(new IdentityRole(RoleManagement.Adminuser)); } if (!await _rolemanager.RoleExistsAsync(RoleManagement.Profuser)) { await _rolemanager.CreateAsync(new IdentityRole(RoleManagement.Profuser)); } await _userManager.AddToRoleAsync(user, RoleManagement.Adminuser); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new Utilisateur { UserName = Input.Email, Email = Input.Email, datenaissance = Input.Datenaissance, statut = Input.Statut }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { var createduser = await _context.Aspnetusers.Where(s => s.Id == user.Id) .FirstOrDefaultAsync(); // if(Input.Statut == "Professeur") // { var professeur = new Model.Professeur { Nom = Input.Nom, Prenom = Input.Prenom, Dateembauche = Input.DateEmbauche, UtilisateurId = createduser.Id, Matericule = Input.Matricule, MatiereId = Input.MatiereId }; _context.Professeur.Add(professeur); await _context.SaveChangesAsync(); _logger.LogInformation("Prof created a new account with password."); _logger.LogInformation(createduser.Id); /* } * else * { * var administrateur = new Model.Administrateur { Nom = Input.Nom, Prenom = Input.Prenom, UtilisateurId = createduser.Id}; * _context.Administrateur.Add(administrateur); * await _context.SaveChangesAsync(); * _logger.LogInformation("Prof created a new account with password."); * _logger.LogInformation(createduser.Id); * }*/ 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 }, 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>."); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email })); } 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()); }