public async Task<IHttpActionResult> Register(UserDto model)
        {
            string message = "";

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

            var user = new ApplicationUser()
            {
                UserName = model.Username,
                Email = model.Email,
                FirstName = model.Firstname,
                LastName = model.Lastname,
                JoinDate = DateTime.UtcNow
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
            else
            {
                var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                var encodedToken = HttpUtility.UrlEncode(code);

                string callback = "http://localhost:9095/confirm?userId={0}&code={1}";

                var url = string.Format(callback, user.Id, encodedToken);
                message = "Please click this link or paste into a browser: <a href='" + url + "'>" + url + "</a>";

                if (!string.IsNullOrEmpty(user.Id))
                {
                    UserManager.AddToRole(user.Id, "User");
                    UserDetail ud = (UserDetail)model;
                    ud.Id = user.Id;

                    await _userRepository.InsertUser(ud);
                    MostRecentUserDto rt = (MostRecentUserDto)model;
                    await _redis.InsertMostRecentUser(rt);
                }
            }

            await UserManager.EmailService.SendAsync(new IdentityMessage() { Subject = "You've been Registered.", Destination = user.Email, Body = message });

            var ret = new
            {
                success = true
            };

            return Ok(ret);
        }
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }
        public async Task<IHttpActionResult> QuickRegister(RegisterUserDto model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if(model == null)
            {
                return BadRequest();
            }

            var user = new ApplicationUser()
            {
                UserName = model.UserName,
                Email = model.Email,
                JoinDate = DateTime.UtcNow
            };

            await UserManager.QuickRegistration(user, model.Password);

            var ret = new
            {
                success = true
            };

            return Ok(ret);
        }