public static ApplicationUser FillEntitie(UserModel userModel)
        {
            return new ApplicationUser
            {
                UserName = userModel.UserName,
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                Email = userModel.Email,
                JoinDate = userModel.JoinDate,
                Active = userModel.Active,
                EmailConfirmed = userModel.EmailConfirmed,
                Id = userModel.Id,
                ImgName = userModel.ImgName

            };
        }
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {

            if (string.IsNullOrEmpty(userModel.Id))
                userModel.Id = Guid.NewGuid().ToString();

            ApplicationUser user = new ApplicationUser
            {
                UserName = userModel.UserName,
                Email = userModel.Email,
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                EmailConfirmed = userModel.EmailConfirmed,
                Active = userModel.Active,
                JoinDate = DateTime.Now,
                Id = userModel.Id
            };

            var result = await _userManager.CreateAsync(user, userModel.Password);
            await _ctx.SaveChangesAsync();
            return result;
        }
 internal async Task<IdentityResult> UpdateAsync(UserModel userModel)
 {
     var user = FindUserById(userModel.Id);
     user.UserName = userModel.UserName;
     user.FirstName = user.FirstName;
     user.LastName = user.LastName;
     user.Email = userModel.Email;
     user.EmailConfirmed = userModel.EmailConfirmed;
     user.Active = userModel.Active;
     user.ImgName = userModel.ImgName;
     var result = await _userManager.UpdateAsync(user);
     return  result;
 }
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var verifiedAccessToken = await VerifyExternalAccessToken(model.Provider, model.ExternalAccessToken);
            if (verifiedAccessToken == null)
            {
                return BadRequest("Invalid Provider or External Access Token");
            }

            IdentityUser user = await _repo.FindAsync(new UserLoginInfo(model.Provider, verifiedAccessToken.user_id));

            bool hasRegistered = user != null;

            if (hasRegistered)
            {
                return BadRequest("External user is already registered");
            }

            var newUser = new UserModel { UserName = model.UserName };

            var result = await _repo.RegisterUser(newUser);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            var info = new ExternalLoginInfo()
            {
                DefaultUserName = model.UserName,
                Login = new UserLoginInfo(model.Provider, verifiedAccessToken.user_id)
            };

            result = await _repo.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            //generate access token response
            var accessTokenResponse = GenerateLocalAccessTokenResponse(model.UserName);

            return Ok(accessTokenResponse);
        }
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IdentityResult result = await _repo.RegisterUser(userModel);

            IHttpActionResult errorResult = GetErrorResult(result);

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

            return Ok();
        }