예제 #1
0
        public async Task <IActionResult> SignUp([Bind("Id,DisplayName,Email,Password,ConfirmPassword,UserType")] User UserToCreate)
        {
            // Check that we got all the parameters that we need
            if (ModelState.IsValid)
            {
                // Check that the email does not exist
                var check = _context.User.FirstOrDefault(u => u.Email == UserToCreate.Email);
                if (check == null)
                {
                    var NewUser = new User();
                    NewUser.Email       = UserToCreate.Email;
                    NewUser.Password    = UserToCreate.Password;
                    NewUser.DisplayName = UserToCreate.DisplayName;
                    NewUser.UserType    = "User";

                    _context.User.Add(NewUser);
                    await _context.SaveChangesAsync();

                    CreateCookie(NewUser);
                    return(RedirectToAction("UserHome", "Home"));
                }
                else
                {
                    ViewBag.error = "User already exists!";
                }
            }

            return(View());
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Genre,ImageLink,ArtistLink")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(artist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Username,Password,ConfirmPassword,UserType")] Admin admin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(admin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(admin));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,ArtistId,Date,Lat,Long,Country,City,AddressName,Description")] Concert concert)
        {
            if (ModelState.IsValid)
            {
                _context.Add(concert);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArtistId"] = new SelectList(_context.Artist, "Id", "Id", concert.ArtistId);
            return(View(concert));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,CounterPlayed,LinkToPlay,AlbumId")] Song song)
        {
            if (ModelState.IsValid)
            {
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AlbumId"] = new SelectList(_context.Set <Album>(), "Id", "Name", song.AlbumId);
            return(View(song));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Release_Date,Genre,ImageLink,AlbumLink,ArtistId")] Album album)
        {
            if (ModelState.IsValid)
            {
                _context.Add(album);
                await _context.SaveChangesAsync();

                //tweet about new Album
                _tweetsController.Tweet(album.Name);
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArtistId"] = new SelectList(_context.Artist, "Id", "Name", album.ArtistId);
            return(View(album));
        }
예제 #7
0
        public async Task <IActionResult> CreatePlaylistAjax(String Name)
        {
            var userId = User.Claims.FirstOrDefault(c => c.Type == "Id")?.Value;

            if (userId != null)
            {
                // Identify the creation of suggested playlist
                if (Name == "suggested")
                {
                    // Create the playlist if it does not exist
                    var isExist = await _context.Playlist.FirstOrDefaultAsync(m => m.Name == "suggested" && m.User.Id.ToString() == userId);

                    // Collected recommended songs

                    // Get all playlists of the user
                    var list_of_playlists = (from n in _context.Playlist where n.UserId.ToString() == userId select n.Id);


                    // Get all the songs that matches all the playlists that belong to this user
                    var list_of_songs = (from a in _context.SongToPlaylist
                                         where list_of_playlists.Contains(a.PlaylistId)
                                         join s in _context.Song on a.SongId equals s.Id
                                         select s.AlbumId);


                    // Get the top 5 most listened to songs
                    if (!list_of_playlists.Any() || !list_of_songs.Any())
                    {
                        list_of_songs = _context.Song.Include(a => a.Album).OrderByDescending(s => s.CounterPlayed).Select(s => s.Album.Id).Take(5);
                    }

                    // Get the top genre out of all the songs that belong to the user by taking the album's genre
                    var top_genre = (from album in _context.Album
                                     where list_of_songs.Contains(album.Id)
                                     group album by album.Genre into genre
                                     orderby genre.Count() descending
                                     select genre.Key).FirstOrDefault();


                    // Getting the top songs
                    var top_songs = _context.Song.Include(a => a.Album).Where(s => s.Album.Genre == top_genre).OrderByDescending(s => s.CounterPlayed).Take(5).ToList();

                    // Create the suggested playlist
                    if (isExist != null)
                    {
                        // Get the existing suggested playlist id
                        var suggestedPlaylistToRemove = await _context.Playlist.FirstOrDefaultAsync(m => m.Name == "suggested" && m.User.Id.ToString() == userId);

                        _context.Playlist.Remove(suggestedPlaylistToRemove);
                        await _context.SaveChangesAsync();
                    }

                    // Create a new suggested playlist
                    Playlist new_suggested_playlist = new Playlist();
                    new_suggested_playlist.Name = Name;

                    new_suggested_playlist.UserId = int.Parse(userId);
                    Random suggested_rnd = new Random();
                    new_suggested_playlist.ImageId = suggested_rnd.Next(1, 16);

                    _context.Add(new_suggested_playlist);
                    await _context.SaveChangesAsync();

                    foreach (var s in top_songs)
                    {
                        var addSong = new SongToPlaylist();
                        addSong.SongId     = s.Id;
                        addSong.PlaylistId = new_suggested_playlist.Id;
                        _context.Add(addSong);
                        await _context.SaveChangesAsync();
                    }

                    return(Json(new { success = true }));
                }

                else
                {
                    Playlist new_playlist = new Playlist();
                    new_playlist.Name = Name;

                    new_playlist.UserId = int.Parse(userId);
                    Random rnd = new Random();
                    new_playlist.ImageId = rnd.Next(1, 16);

                    _context.Add(new_playlist);
                    await _context.SaveChangesAsync();

                    return(Json(new { success = true }));
                }
            }
            return(Json(new { success = false }));
        }
예제 #8
0
        public async Task <IActionResult> AddSongToPlaylistAjax(String playlistId, String songId)
        {
            int flag          = 0;
            int intSongId     = 0;
            int intPlaylistId = 0;

            // Attempt to convert variables to integers
            try
            {
                intSongId     = int.Parse(songId);
                intPlaylistId = int.Parse(playlistId);
            }

            catch
            {
                flag = 2;
            }

            var userId = User.Claims.FirstOrDefault(c => c.Type == "Id")?.Value;

            if (userId != null)
            {
                // Verify that the user own the playlist
                var playlist = _context.Playlist.FirstOrDefault(p => p.Id == intPlaylistId && p.UserId.ToString() == userId);

                if (playlist != null)
                {
                    // Verify that the song does not exist in the playlist
                    var isSongInPlaylist = _context.SongToPlaylist.FirstOrDefault(s => s.PlaylistId == intPlaylistId && s.SongId == intSongId);


                    // Song not in playlist so we can add it
                    if (isSongInPlaylist == null)
                    {
                        var addSong = new SongToPlaylist();
                        addSong.SongId     = intSongId;
                        addSong.PlaylistId = intPlaylistId;
                        _context.Add(addSong);
                        await _context.SaveChangesAsync();
                    }

                    else
                    {
                        flag = 1;
                    }
                }
            }
            if (flag == 0)
            {
                return(Json(new { success = true }));
            }

            else if (flag == 1)
            {
                return(Json(new { success = false }));
            }

            else
            {
                return(RedirectToAction("Error404", "Home"));
            }
        }