title: ASP.NET how to access AspNetUsers table and return values
body: <p>Successfully I added some fields in AspNetUsers  table but I don't know how I can retrieve them. My project is asp.net web api and I can retrieve username from token. I want to return departmentId by given userId, or username.
  and trying like but this gives me null exeption</p>
  
  <pre><code>   private ApplicationUserManager _userManager;
  
  
          public int GetdeptId(string username)
          {
             var dept =  _userManager.Users.Where(d =&gt; d.UserName == username).Select(c =&gt; c.DepartmentId).FirstOrDefault();
              return dept;
  
  
          }
  </code></pre>
  
  <p>Here is the way I could create fields in my AspNetUsers and I can insert values successfully. The problem is to return values from AspNetUsers.</p>
  
  <pre><code>public class RegisterBindingModel
      {
          [Required]
          [Display(Name = "Email")]
          public string Email { get; set; }
  
          [Required]
          [Display(Name = "FirstName")]
          public string FirstName { get; set; }
  
          [Required]
          [Display(Name = "Lastname")]
          public string Lastname { get; set; }
  
          [Required]
          [Display(Name = "Department")]
          public int DepartmentId { get; set; }
  
  
  
          [Required]
          [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [DataType(DataType.Password)]
          [Display(Name = "Password")]
          public string Password { get; set; }
  
          [DataType(DataType.Password)]
          [Display(Name = "Confirm password")]
          [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
          public string ConfirmPassword { get; set; }
      }
  </code></pre>
  
  <p>And then the registerration</p>
  
  <pre><code>public async Task&lt;IHttpActionResult&gt; Register(RegisterBindingModel model)
          {
              if (!ModelState.IsValid)
              {
                  return BadRequest(ModelState);
              }
  
              var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, Firstname = model.FirstName, LastName =        model.Lastname, DepartmentId = model.DepartmentId };
  
              IdentityResult result = await UserManager.CreateAsync(user, model.Password);
  
              if (!result.Succeeded)
              {
                  return GetErrorResult(result);
              }
  
              return Ok();
          } 
  </code></pre>
  
  <p>Thank you in advance!</p>