public async Task <IActionResult> PutUsers(int id, ApiUsers users) { if (id != users.UserId) { return(BadRequest("User does not exist.")); } var resource = ApiMapper.MapUsers(users); try { await _repo.UpdateUserAsync(resource); } catch (DbUpdateConcurrencyException) { if (!await _repo.UserExistAsync(id)) { return(NotFound("User not found.")); } else { throw; } } return(Ok("User updated.")); }
public async Task <ActionResult> PostUsers(ApiUsers users) { try { var resource = ApiMapper.MapUsers(users); await _repo.AddUserAsync(resource); return(Ok("User added!")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult> GetUsers(int id) { try { if (await _repo.GetUserById(id) is CoreUsers sub) { var resource = ApiMapper.MapUsers(sub); return(Ok(resource)); } } catch (NullReferenceException) { return(NotFound($"No Users with an id of {id} was found.")); } return(Ok("There are no Users.")); }