0

Say I have a model like this:

public class Person
{
   public int Id {get; set}
   public int Username {get; set;}
   //...other props
}

For a POST method, how can model state validation be used to ensure that a given username is not already used? Surely it will require a database lookup, but what is a simple, clean pattern for achieving this?

Second question: how can the same be achieved in a PUT method, where the lookup logic should ignore the one record that is being updated, since it obviously exists in the DB?

BCA
  • 7,776
  • 3
  • 38
  • 53

0 Answers0