public async Task SetCurrentUser()
        {
            var spotifyClient = await _spotifyClientBuilder.CreateClient();

            var user = await spotifyClient.UserProfile.Current();

            _currentUser.UserId = user.Id;
        }
        // POST: Users/Create
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.


        public async Task <IActionResult> Build()
        {
            var spotify = await _spotifyClientBuilder.CreateClient();

            if (spotify == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            PrivateUser me = await spotify.UserProfile.Current();

            _user.UserId   = me.Id;
            _user.UserName = me.DisplayName;
            if (me.Images.Any())
            {
                _user.UserProfilePicture = me.Images[0].Url;
            }
            else
            {
                _user.UserProfilePicture = "";
            }



            var user = await _context.Users
                       .FirstOrDefaultAsync(m => m.UserId == me.Id);

            var userNum = _context.Users.Count() + 1;

            _user.UserCode = GenerateUserCode(me.Id) + userNum.ToString();

            if (user == null)
            {
                PersonalizationTopRequest request = new PersonalizationTopRequest();
                request.Limit = 50;

                var tracks = await spotify.Personalization.GetTopTracks(request);

                List <FullTrack> .Enumerator tracksEnumerator = tracks.Items.GetEnumerator();



                var trackNumbers = tracks.Items.Count;
                for (int i = 0; i < trackNumbers; i++)
                {
                    tracksEnumerator.MoveNext();

                    if (tracksEnumerator.Current != null)
                    {
                        //creating a new track and userTracks to map tracks and users
                        Track     newTrack   = new Track();
                        UserTrack userTracks = new UserTrack();

                        //initializing tracks one bu one
                        newTrack.TrackId   = tracksEnumerator.Current.Id;
                        newTrack.TrackName = tracksEnumerator.Current.Name;
                        if (tracksEnumerator.Current.Album.Images.Any())
                        {
                            newTrack.TrackAlbumPicture = tracksEnumerator.Current.Album.Images[0].Url;
                        }
                        else
                        {
                            newTrack.TrackAlbumPicture = "";
                        }
                        newTrack.TrackAlbumPicture = tracksEnumerator.Current.Album.Images[0].Url;

                        //adding track and user to UserTracks model initializing userTracks
                        userTracks.Track = newTrack;
                        userTracks.User  = _user;

                        //adding userTracks to User model
                        _user.UsersTracks.Add(userTracks);

                        //adding userTracks to Track model
                        newTrack.UsersTracks.Add(userTracks);
                        //check if artist exists in db
                        var trackExists = _context.Tracks.Count(a => a.TrackId == newTrack.TrackId);
                        if (trackExists == 0)
                        {
                            await _context.Tracks.AddAsync(newTrack);
                        }
                        else
                        {
                            _context.Tracks.Update(newTrack);
                        }
                    }
                }

                //now put top artist to database

                var artists = await spotify.Personalization.GetTopArtists(request);

                List <FullArtist> .Enumerator artistsEnumerator = artists.Items.GetEnumerator();

                var artistCount = artists.Items.Count;
                for (int i = 0; i < artistCount; i++)
                {
                    artistsEnumerator.MoveNext();

                    if (artistsEnumerator.Current != null)
                    {
                        //creating a new track and userTracks to map tracks and users
                        Artist     newArtist  = new Artist();
                        UserArtist userArtist = new UserArtist();

                        //initializing tracks one bu one
                        newArtist.ArtistId   = artistsEnumerator.Current.Id;
                        newArtist.ArtistName = artistsEnumerator.Current.Name;

                        if (artistsEnumerator.Current.Images.Any())
                        {
                            newArtist.ArtistPicture = artistsEnumerator.Current.Images[0].Url;
                        }
                        else
                        {
                            newArtist.ArtistPicture = "";
                        }
                        //adding track and user to UserTracks model initializing userTracks
                        userArtist.Artist = newArtist;
                        userArtist.User   = _user;

                        //adding userTracks to User model
                        _user.UsersArtists.Add(userArtist);

                        //adding userTracks to Track model
                        newArtist.UsersArtists.Add(userArtist);

                        //check if artist exists in db
                        var artistExists = _context.Artists.Count(a => a.ArtistId == newArtist.ArtistId);
                        if (artistExists == 0)
                        {
                            await _context.Artists.AddAsync(newArtist);
                        }
                        else
                        {
                            _context.Artists.Update(newArtist);
                        }
                    }
                }

                await _context.Users.AddAsync(_user);

                await _context.SaveChangesAsync();

                return(RedirectToAction(actionName: "Home", "Users", new { id = _user.UserId }));
            }



            return(RedirectToAction(actionName: "Home", "Users", new { id = _user.UserId }));
        }