public async Task<IHttpActionResult> Register(CreateUserModel createUserModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var result = await repo.RegisterUser(createUserModel);

            var errorResult = GetErrorResult(result.Result);

            if (errorResult != null)
            {
                return errorResult;
            }

            return Ok(result.User.Id);
        }
 public async Task<RegisterResult> RegisterUser(CreateUserModel createUserModel)
 {
     var user = new IdentityUser
     {
         UserName = createUserModel.UserName
     };
     
     var result = await userManager.CreateAsync(user, createUserModel.Password);
     if (result.Succeeded)
     {
         var rolesToAdd = db.Roles.Where(x => createUserModel.Roles.Contains(x.Id));
         var dbUser = db.Users.Find(user.Id);
         dbUser.Roles.AddRange(rolesToAdd);
         await db.SaveChangesAsync();
     }
     return new RegisterResult {Result = result, User = user};
 }