public async Task <ActionResult> Post([FromBody] Student student) { if (ModelState.IsValid) { if (!PasswordSecurity.CheckPasswordPolicy(student.Password)) { ModelState.AddModelError("Errors", "PASSWORD INVALID"); return(BadRequest(ModelState)); } if (_context.EmailIsTaken(student.Email)) { ModelState.AddModelError("Errors", "Email has already been taken"); return(BadRequest(ModelState)); } student.Password = PasswordSecurity .HashPassword(student.Password); student.EmailConfirmed = false; await _context.AddAsync(student); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = student.StudentId }, student)); } return(BadRequest()); }
public async Task <ActionResult> Post([FromBody] Administrator administrator) { if (ModelState.IsValid) { if (!PasswordSecurity.CheckPasswordPolicy(administrator.Password)) { ModelState.AddModelError("Errors", "PASSWORD INVALID"); return(BadRequest(ModelState)); } if (_context.EmailIsTaken(administrator.Email)) { ModelState.AddModelError("Errors", "Email has already been taken"); return(BadRequest(ModelState)); } administrator.Password = PasswordSecurity .HashPassword(administrator.Password); await _context.AddAsync(administrator); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = administrator.AdministratorId }, administrator)); } return(BadRequest()); }