public async Task <IActionResult> RegisterStudent(StudentViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                var user = new Student()
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    IndexNumber = model.IndexNumber,
                    Email       = model.Email,
                    UserName    = model.UserName
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("You have created a new account with role student.");


                    IdentityRole userRole = _context.Roles.SingleOrDefault(r => r.Name.ToLower().Equals("student"));

                    _context.UserRoles.Add(new IdentityUserRole <string>()
                    {
                        RoleId = userRole.Id, UserId = user.Id
                    });
                    _context.SaveChanges();

                    return(View("RegisterStudentSuccessful", model));
                }

                return(View(model));
            }
            return(View("./Error"));
        }
        public ProfessorSubject Delete(string professorId, long subjectId)
        {
            try
            {
                var professorSubject = _context.ProfessorSubjects.Find(professorId, subjectId);
                _context.ProfessorSubjects.Remove(professorSubject);
                _context.SaveChanges();

                return(professorSubject);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error while trying to delete relation between professor and subject! Error: {ex.Message}");
            }
        }
Exemple #3
0
 public Subject Delete(long subjectId)
 {
     try
     {
         Subject requestedSubject = _context.Subjects
                                    .FirstOrDefault(s => s.SubjectId == subjectId);
         if (requestedSubject != null)
         {
             _context.Remove(requestedSubject);
             _context.SaveChanges();
             return(requestedSubject);
         }
         throw new Exception("Subject that you want to delete doesn't exist!");
     }
     catch (Exception ex)
     {
         throw new Exception($"Error while trying to find subject! Error: {ex.Message}");
     }
 }
 public Professor Delete(string professorId)
 {
     try
     {
         Professor requestedProfessor = _context.Professors
                                        .FirstOrDefault(p => p.Id.Equals(professorId));
         if (requestedProfessor != null)
         {
             _context.Remove(requestedProfessor);
             _context.SaveChanges();
             return(requestedProfessor);
         }
         throw new Exception("Professor that you want to delete doesn't exist!");
     }
     catch (Exception ex)
     {
         throw new Exception($"Error while trying to delete professor! Error: {ex.Message}");
     }
 }
Exemple #5
0
 public Student Delete(string studentId)
 {
     try
     {
         Student requestedStudent = _context.Students
                                    .FirstOrDefault(p => p.Id.Equals(studentId));
         if (requestedStudent != null)
         {
             _context.Remove(requestedStudent);
             _context.SaveChanges();
             return(requestedStudent);
         }
         throw new Exception("Student that you want to delete doesn't exist!");
     }
     catch (Exception ex)
     {
         throw new Exception($"Error while trying to find student! Error: {ex.Message}");
     }
 }
Exemple #6
0
 public void Insert(SeminarPaper seminarPaper)
 {
     _context.SeminarPapers.Add(seminarPaper);
     _context.SaveChanges();
 }