title: How to allow user to register with duplicate UserName using Identity Framework 1.0
body: <p>I want to develop an application in MVC using Identity Framework 1.0 which allow users to register with same username used by some other user.</p>
  
  <p>When deleting a user I want to set its <code>IsDeleted</code> custom property to true rather than deleting the user from database. In this case another user can use the <code>UserName</code> of the user whose <code>IsDeleted</code> is set to true.</p>
  
  <p>But the default <code>UserManager.CreateAsync(user, password);</code> method is preventing doing this.</p>
  
  <p>I had overridden the <code>ValidateEntity</code> method of <code>IdentityDbContext</code> like this</p>
  
  <pre><code>protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary&lt;object, object&gt; items)
  {
      if ((entityEntry != null) &amp;&amp; (entityEntry.State == EntityState.Added))
      {
          ApplicationUser user = entityEntry.Entity as ApplicationUser;
          if ((user != null) &amp;&amp; this.Users.Any&lt;ApplicationUser&gt;(u =&gt; string.Equals(u.UserName, user.UserName) &amp;&amp; u.IsDeleted==false))
          {
              return new DbEntityValidationResult(entityEntry, new List&lt;DbValidationError&gt;()) {
                  ValidationErrors = { 
                      new DbValidationError("User", string.Format(CultureInfo.CurrentCulture, 
                         "", new object[] { user.UserName }))
                  } 
              };
          }
          IdentityRole role = entityEntry.Entity as IdentityRole;
          if ((role != null) &amp;&amp; this.Roles.Any&lt;IdentityRole&gt;(r =&gt; string.Equals(r.Name, role.Name)))
          {
              return new DbEntityValidationResult(entityEntry, new List&lt;DbValidationError&gt;()) { 
                  ValidationErrors = { 
                      new DbValidationError("Role", string.Format(CultureInfo.CurrentCulture, 
                          "", new object[] { role.Name })) } };
          }
      }
      return base.ValidateEntity(entityEntry, items);
  }
  </code></pre>
  
  <p>Here is my register method where user is created</p>
  
  <pre><code>public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
  {
      if (ModelState.IsValid)
      {
          var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email.ToLower(), CreatedBy = model.UserName, CreatedDate = DateTime.UtcNow, };
  
          user.ConfirmedEmail = false;
          var result = await _accountService.CreateAsync(user, model.Password);
          if (result.Succeeded)
          {
  
              TempData["MessageConfirm"] = user.Email;
              return RedirectToAction("Confirm", "Account");
          }
          else
          {
              AddErrors(result);
          }
      }
      // If we got this far, something failed, redisplay form
      return View(model);
  }
  </code></pre>
  
  <p><code>ValidateEntity</code> method should be executed when <code>await _accountService.CreateAsync(user, model.Password);</code> executes. But it is executing after the <code>register</code> method completes it's execution. So the result throws error.</p>
  
  <p>Any suggestions how I can achieve this?</p>