title: How to check phone number is unique in AspNetUsers table when using ASP.NET Web Api
body: <p>I have created an Asp.Net Web Api project and used Individual user accounts.
  When I am adding users to the table the default system automatically checks if the email address supplied already exists in the table, if so a bad request is thrown otherwise the user can be submitted.</p>
  
  <p>How can I also check if the Phone Number is unique and hasn't already been submitted to the table?</p>
  
  <pre><code>// POST api/Account/Register
          [AllowAnonymous]
          [Route("Register")]
          public async Task&lt;IHttpActionResult&gt; Register(RegisterBindingModel model)
          {
              if (!ModelState.IsValid)
              {
                  return BadRequest(ModelState);
              }
  
              **using (ApplicationDbContext db = new ApplicationDbContext())
              {
                  var foundPhoneNumber = await db.Users.FirstOrDefaultAsync(x =&gt; x.PhoneNumber.Equals(model.PhoneNumber));
  
                  if (foundPhoneNumber != null)
                  {
                      return BadRequest("Phone number already exists");
                  }
              }**
  
              var user = new ApplicationUser()
              {
                  UserName = model.Email,
                  Email = model.Email,
                  PhoneNumber = model.PhoneNumber,
                  FirstName = model.FirstName,
                  LastName = model.LastName,
                  MemberNumber = model.MemberNumber,
                  CarReg = model.CarReg
              };
  
              IdentityResult result = await UserManager.CreateAsync(user, model.Password);
  
              if (!result.Succeeded)
              {
                  return GetErrorResult(result);
              }
  
              return Ok();
          }
  </code></pre>
  
  <p>I have queried the database to check if there is a Phone Number with the same number. This works, but is there a better way to do this?</p>