Exemplo n.º 1
0
        public ApplicationUser CreateUser(string username, string password)
        {
            var existingUser = this.DbContext.Users.SingleOrDefault(x => x.Username == username);

            if (existingUser != null)
            {
                throw HttpResponseExceptionHelper.Create("This username is already taken", HttpStatusCode.BadRequest);
            }

            var newUser = new ApplicationUser
            {
                Username = username,
                Id       = ApplicationUserManager.GetUserHash(username),
                Password = ApplicationUserManager.HashUserPassword(password)
            };

            this.DbContext.Users.Add(newUser);
            this.DbContext.SaveChanges();

            AzureBlobStorageHelper.UploadDefaultAvatar(newUser.Id);

            return(newUser);
        }