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> TauxAbsEtu() { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; Model.Professeur pr = await _context.Professeur.FirstOrDefaultAsync(x => x.UtilisateurId == userId); IEnumerable <AdminDashboardViewModel> v1 = await(from ab in _context.Absance join etu in _context.Etudiant on ab.EtudiantIdEtudiant equals etu.IdEtudiant join se in _context.Seance on ab.SeanceIdSeance equals se.IdSeance join p in _context.Professeur on se.ProfesseurId equals p.IdProfesseur join m in _context.Matiere on p.MatiereId equals m.IdMatiere where p.IdProfesseur == pr.IdProfesseur select new AdminDashboardViewModel() { Countabs = etu.Absance.Count() }).ToListAsync(); IEnumerable <AdminDashboardViewModel> v2 = await(from ab in _context.Absance join etu in _context.Etudiant on ab.EtudiantIdEtudiant equals etu.IdEtudiant join se in _context.Seance on ab.SeanceIdSeance equals se.IdSeance join p in _context.Professeur on se.ProfesseurId equals p.IdProfesseur join m in _context.Matiere on p.MatiereId equals m.IdMatiere where ab.EstAbsant == 0 select new AdminDashboardViewModel() { NomComplet = etu.Nom + " " + etu.Prenom, EstAbsent = ab.EstAbsant, NbAbsEtu = _context.Absance.Where(n => n.EtudiantIdEtudiant == etu.IdEtudiant && n.EstAbsant == 0 && n.SeanceIdSeanceNavigation.ProfesseurId == pr.IdProfesseur).Count(), }).ToListAsync(); IEnumerator <AdminDashboardViewModel> enumerator = v1.GetEnumerator(); IEnumerator <AdminDashboardViewModel> enumerator2 = v2.GetEnumerator(); while (enumerator2.MoveNext() && enumerator.MoveNext()) { enumerator2.Current.Countabs = enumerator2.Current.NbAbsEtu / enumerator.Current.Countabs * 100; } return(View(v2)); }
public async Task <IActionResult> TauxAbsMat() { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; Model.Professeur pr = await _context.Professeur.FirstOrDefaultAsync(x => x.UtilisateurId == userId); IEnumerable <AdminDashboardViewModel> v1 = await(from ab in _context.Absance join se in _context.Seance on ab.SeanceIdSeance equals se.IdSeance join p in _context.Professeur on se.ProfesseurId equals p.IdProfesseur join m in _context.Matiere on p.MatiereId equals m.IdMatiere select new AdminDashboardViewModel() { LibelleMatiere = m.Libelle, Countabs = _context.Absance.Where(n => n.SeanceIdSeanceNavigation.Professeur.Matiere.IdMatiere == m.IdMatiere && n.SeanceIdSeanceNavigation.Professeur.IdProfesseur == pr.IdProfesseur).Count() }).Distinct().ToListAsync(); IEnumerable <AdminDashboardViewModel> v2 = await(from ab in _context.Absance join se in _context.Seance on ab.SeanceIdSeance equals se.IdSeance join p in _context.Professeur on se.ProfesseurId equals p.IdProfesseur join m in _context.Matiere on p.MatiereId equals m.IdMatiere select new AdminDashboardViewModel() { LibelleMatiere = m.Libelle, Countabs = _context.Absance.Where(n => n.SeanceIdSeanceNavigation.Professeur.Matiere.IdMatiere == m.IdMatiere && n.SeanceIdSeanceNavigation.Professeur.IdProfesseur == pr.IdProfesseur && n.EstAbsant == 0).Count() }).Distinct().ToListAsync(); IEnumerator <AdminDashboardViewModel> enumerator = v1.GetEnumerator(); IEnumerator <AdminDashboardViewModel> enumerator2 = v2.GetEnumerator(); while (enumerator2.MoveNext() && enumerator.MoveNext()) { enumerator2.Current.Countabs = enumerator2.Current.Countabs / enumerator.Current.Countabs * 100; } return(View(v2)); }
public async Task <IActionResult> ListePresence() { var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; Model.Professeur pr = await _context.Professeur.FirstOrDefaultAsync(x => x.UtilisateurId == userId); var results = await(from ab in _context.Absance join se in _context.Seance on ab.SeanceIdSeance equals se.IdSeance join p in _context.Professeur on se.ProfesseurId equals p.IdProfesseur join m in _context.Matiere on p.MatiereId equals m.IdMatiere join etu in _context.Etudiant on ab.EtudiantIdEtudiant equals etu.IdEtudiant where p.IdProfesseur == pr.IdProfesseur select new AdminDashboardViewModel() { LibelleMatiere = m.Libelle, DateSeance = ab.DateAbsance, NomComplet = etu.Nom + " " + etu.Prenom, EstAbsent = ab.EstAbsant, }).ToListAsync(); return(View(results)); }
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()); }