public async Task <IActionResult> Put(int appointmentId, [FromBody] AppointmentUpdateStatus appointmentDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var appointment = await _context.Appointments.FindAsync(appointmentId); if (appointment == null) { return(NotFound()); } if (appointment.StatusId == (int)StatusEnum.Cancel) { return(BadRequest("Cannot update cancel status")); } appointment.StatusId += 1; if (appointment.StatusId == (int)StatusEnum.Done) { appointment.Feedback = appointmentDto.Feedback; } await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Register([FromBody] RegisterUserDto registerUserDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newUser = new User() { Email = registerUserDto.Email, RoleId = registerUserDto.RoleId, Name = registerUserDto.Name }; var passwordHash = _passwordHasher.HashPassword(newUser, registerUserDto.Password); newUser.PasswordHash = passwordHash; await _context.Users.AddAsync(newUser); await _context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); }