public async Task <IActionResult> Update(int id, PutUserParam u) { try { if (id != u.Id) { return(BadRequest()); } DataAccess.Models.User user = await _context.Users.FindAsync(id); if (user != null) { user.Name = u.Name; _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); } return(NotFound($"Could not find user {id}")); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
public ActionResult <UserDto> PutUser2(Guid id, PutUserParam param) { var user = (EndUser)_userRepository.GetUser(id); user.AuthenticateWhenUnlockingScreen = (bool)param.AuthenticateWhenUnlockingScreen; _userRepository.Update(user); return(Ok(new UserDto(user))); }
public ActionResult <UserDto> PutUser(Guid id, PutUserParam param) { var targetUser = (EndUser)_userRepository.GetUser(id); var targetDomain = _userRepository.GetDomain(targetUser.Domain.Id); var loginUser = (EndUser)_userRepository.GetUser(Guid.Parse(User.Identity.Name)); var loginDomain = _userRepository.GetDomain(loginUser.Domain.Id); if (targetDomain.Organization.Code != loginDomain.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } targetUser.AuthenticateWhenUnlockingScreen = (bool)param.AuthenticateWhenUnlockingScreen; _userRepository.Update(targetUser); return(Ok(new UserDto(targetUser))); }