I have a problem, I made an api in .net 6 and I have a User model, with an incremental Id. I want that when I do a get from a user in swagger, it shows me all the data (including the ID), but if I make a Post I don't want the ID to appear in the body. How can I do it?
public class User
{
[Key]
public int Id { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
try
{
List<User>? user;
using (Context context = new())
{
user = context.Users.ToList();
}
return Ok(user.ToList());
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost]
public IActionResult Post(User value)
{
try
{
using (Context context = new())
{
context.Users.Add(value);
context.SaveChanges();
return Ok();
}
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}