© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
21 replies
Keyvan

Testing my UserEdit Api endpoint using swagger fails and throws a code 400 response

I am trying to use Swagger to test my api endpoints but i get a code 400 when i test them.

[HttpPut("Edit")]
public async Task<ActionResult> UserEdit([FromBody] UserModel user, string password)
{
    var retrievedEntity = _context.Users.Find(user.UserName);
    if (retrievedEntity == null) {
        return NotFound("User was not found in database");
    }
    
    bool changeApproved = Security.VerifyPassword(password, user.Password);
    if (!changeApproved) {
        return BadRequest("Wrong password");
    }

    var userEntity = UserServices.ModelToEntity(user);

    _context.Users.Update(userEntity);
    await _context.SaveChangesAsync();
    return Ok("User successfully updated");
}
[HttpPut("Edit")]
public async Task<ActionResult> UserEdit([FromBody] UserModel user, string password)
{
    var retrievedEntity = _context.Users.Find(user.UserName);
    if (retrievedEntity == null) {
        return NotFound("User was not found in database");
    }
    
    bool changeApproved = Security.VerifyPassword(password, user.Password);
    if (!changeApproved) {
        return BadRequest("Wrong password");
    }

    var userEntity = UserServices.ModelToEntity(user);

    _context.Users.Update(userEntity);
    await _context.SaveChangesAsync();
    return Ok("User successfully updated");
}
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Describing `object` response in swagger
C#CC# / help
2y ago
❔ My asp.net endpoint throws a error when it receives string
C#CC# / help
3y ago
swagger Error: response status is 401
C#CC# / help
2y ago
❔ IHealthCheck and Swagger
C#CC# / help
3y ago