public IActionResult newSong([FromBody] SongViewModel song) { if (ModelState.IsValid) { if (song.EmbedLink.Length >= 12) { song.EmbedLink = LinkToEmbed(song.EmbedLink); } Song songInstance = new Song { Artist = song.Artist, Title = song.Title, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, EmbedLink = song.EmbedLink, Description = song.Description, Genre = song.Genre, UserId = (int)HttpContext.Session.GetInt32("userID") }; _context.Songs.Add(songInstance); _context.SaveChanges(); int success = 1; return(new ObjectResult(success)); } return(NotFound()); }
public int Add(Playlist playlist) { _context.Playlists.Add(playlist); int id = _context.SaveChanges(); return(id); }
public void a_AddToPlaylist() { string result = null; try { using (var transaction = context.Database.BeginTransaction()) { PlaylistMusic pm = new PlaylistMusic { Id = -1, MusicId = -1, PlaylistId = -1 }; context.PlaylistMusics.Add(pm); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.PlaylistMusic ON;"); context.SaveChanges(); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.PlaylistMusic OFF;"); transaction.Commit(); result = "ok"; } } catch (Exception e) { result = e.ToString(); } Assert.True(result == "ok", result); }
public void a_Insert() { string result = null; try { using (var transaction = context.Database.BeginTransaction()) { Playlist playlist = new Playlist { AudioPlayerProjectUserId = "test_id", Id = -1, Name = "test_name" }; context.Playlists.Add(playlist); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Playlist ON;"); context.SaveChanges(); context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT dbo.Playlist OFF;"); transaction.Commit(); result = "ok"; } } catch (Exception e) { result = e.ToString(); } Assert.True(result == "ok", result); }
public IActionResult Index(Playlist playlist) { TempData["ConfirmationResult"] = new string[] { "danger", "Une erreur s'est produite lors de la création de la playlist." }; try { string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); /* Check if a playlist with this name already exists in database */ bool playlistAlreadyExist = context.Playlists.ToList().Where(p => p.AudioPlayerProjectUserId == userId && p.Name == playlist.Name).Any(); if (playlistAlreadyExist) { TempData["ConfirmationResult"] = new string[] { "danger", "Une playlist de ce nom existe déjà." }; return(RedirectToAction()); } playlist.AudioPlayerProjectUserId = userId; context.Playlists.Add(playlist); context.SaveChanges(); TempData["ConfirmationResult"] = new string[] { "success", "La playlist a été créée avec succès !" }; ModelState.Clear(); } catch (Exception e) { Console.WriteLine(e.ToString()); } return(RedirectToAction()); }
public String CreatePlaylist(Playlist playlist) { try { _context.Playlists.Add(playlist); _context.SaveChanges(); return("Created"); } catch (Exception ex) { return(ex.Message); } }
public IActionResult Index(int id) { List <Song> UserSongs = new List <Song>(); //validation if (_context.Users.Find(id) != null) { //GenerateRequests(); UserSongs = _context.Songs.Where(s => s.UserId == id).ToList(); } //SendRequestsToDisk(); string downloadUrl = ""; Song currentSong = new Song(); HttpRequestMessage RequestMessage = new HttpRequestMessage(); foreach (var song in UserSongs) { httpClient = new HttpClient(); RequestMessage.RequestUri = new Uri(baseUri + song.Name); RequestMessage.Method = HttpMethod.Get; RequestMessage.Headers.Clear(); RequestMessage.Headers.Add("Authorization", "OAuth AQAAAAAhJOxxAAUoplRt2XN-kE5gkry4Rk2b-vI"); downloadUrl = httpClient.SendAsync(RequestMessage).Result.Content.ReadAsStringAsync().Result; downloadUrl = JsonConvert.DeserializeObject <DownloadUrl>(downloadUrl).href; httpClient.Dispose(); //UpdateDatabase(); currentSong = UserSongs.Find(s => s.Id == song.Id); currentSong.DownloadUrl = downloadUrl; _context.Songs.Update(currentSong); } _context.SaveChanges(); return(View("Index", UserSongs)); }
public void TestInit() { DbContextOptionsBuilder <PlaylistContext> dbContextOptionsBuilder = new DbContextOptionsBuilder <PlaylistContext>() .UseInMemoryDatabase("RoomSong"); Room mockRoom = new Room() { Id = 1, Owner = "Owner", }; Song mockSong = new Song() { Id = 1, Name = "Song1", Artist = "Artist1", }; _mockRoomSong = new RoomSong() { Id = 1, RoomId = 1, Room = mockRoom, Song = mockSong, SongId = 1, }; _playlistContext = new PlaylistContext(dbContextOptionsBuilder.Options); _playlistContext.Database.EnsureDeleted(); _playlistContext.Rooms.Add(mockRoom); _playlistContext.RoomSongs.Add(_mockRoomSong); _playlistContext.Songs.Add(mockSong); _playlistContext.SaveChanges(); _roomSongDataStore = new RoomSongDataStore(_playlistContext); }
public IActionResult AddToPlaylist(int playlist_id, int music_id) { TempData["ConfirmationResult"] = new string[] { "danger", "Une erreur s'est produite lors de l'ajout à une playlist." }; if (UserOwnsPlaylist(playlist_id)) // If user owns this playlist { IEnumerable <PlaylistMusic> listPM = contextPlaylist.PlaylistMusics.ToList().Where(pm => (pm.PlaylistId == playlist_id) && (pm.MusicId == music_id)); if (!listPM.Any()) // Check if music_id isn't already in playlist_id { PlaylistMusic pm = new PlaylistMusic() { MusicId = music_id, PlaylistId = playlist_id }; contextPlaylist.PlaylistMusics.Add(pm); contextPlaylist.SaveChanges(); TempData["ConfirmationResult"] = new string[] { "success", "La musique a été ajoutée à la playlist avec succès !" }; } else { TempData["ConfirmationResult"] = new string[] { "warning", "La musique est déjà dans cette playlist." }; } } else { TempData["ConfirmationResult"] = new string[] { "danger", "La playlist est introuvable." }; } return(RedirectToAction("Index")); }
public IActionResult Add(Song song) { Console.WriteLine("This is the add Song method"); // Fetch the current user User user = fetchuser(); // Check model validations if (ModelState.IsValid) { Console.WriteLine("Validations passed"); // Add the table and save the changes _context.Songs.Add(song); _context.SaveChanges(); // Render the View with the User model return(RedirectToAction("Index")); } // Navbar variables ViewBag.user_name = user.name(); // General Viewbag settings ViewBag.dashboard = true; // Return the original Index SongWrapper songwrapper = new SongWrapper(_context.PopulateSongsAllOrderbyCreatedAt(), song); // Return the view of index with list of auctions attached return(View("Index", songwrapper)); }
public static void LogActivity(PlaylistContext context, string source, string message, Visitor visitor) { Models.Log log = new Models.Log(); log.IdVisitorNavigation = visitor; log.Message = message; log.Source = source; context.Log.Add(log); context.SaveChanges(); }
public IActionResult Index() { var orgStructuredSchema = new Schema.NET.Organization() { Name = "Vole Software", Url = new Uri("https://raprockplaylist.tk"), SameAs = new Uri[3] { new Uri("https://www.instagram.com/raprockplaylist"), new Uri("https://twitter.com/RaprockP"), new Uri("https://linkedin.com/in/martin-hrabovský-210306177") } }; ViewBag.JsonLd = orgStructuredSchema.ToString(); _context.Database.EnsureCreated(); Functions.Log.LogActivity(_context, "Index", "Loaded main page", _accessor); _context.SaveChanges(); return(View()); }
// This handles the register logic private dynamic register(User user) { // Check the form validations if (ModelState.IsValid) { // Let's hash the password user.hash_password(); // Add the user to the database and save changes _context.Users.Add(user); _context.SaveChanges(); // Get the dbuser to grab all the details, including ID User dbuser = _context.Users.Where(item => item.Email == user.Email).SingleOrDefault(); // Store information in Session HttpContext.Session.SetString("registered", "Yes"); HttpContext.Session.SetInt32("user", dbuser.Id); // Redirect to the main users page return(RedirectToAction("Index", "Song")); } UserWrapper wrapper = new UserWrapper(user, new Login()); // Return the view of Register return(View("Index", wrapper)); }
public static void LogError(PlaylistContext context, string source, string message, Visitor visitor) { try { Models.ErrorLog errorLog = new Models.ErrorLog(); errorLog.IdVisitorNavigation = visitor; errorLog.Message = message; errorLog.Source = source; context.ErrorLog.Add(errorLog); context.SaveChanges(); Mail.SendMail("Error", "Source:<br>" + source + "<br>Message:<br>" + message); } catch (Exception e) { Models.ErrorLog errorLog = new Models.ErrorLog(); errorLog.IdVisitorNavigation = visitor; errorLog.Message = e.ToString(); errorLog.Source = "ErrorLogger"; context.ErrorLog.Add(errorLog); context.SaveChanges(); Mail.SendMail("Critical Error", e.ToString()); } }
public ActionResult Post([FromBody] List <Playlist> playlistList) { if (playlistList[0].Id == 1) { } else { List <Playlist> playedSongsList = new List <Playlist>(); for (int i = 0; i < playlistContext.Playlist.ToList().Count; i++) { playedSongsList.Add(playlistContext.Playlist.ToList()[i]); if (playlistContext.Playlist.ToList()[i].WasPlayed == false) { break; } } playedSongsList.AddRange(playlistList); } playlistContext.Playlist.RemoveRange(playlistContext.Playlist.ToList()); playlistContext.Playlist.AddRange(playlistList); playlistContext.SaveChanges(); return(Ok()); }
public void TestInit() { var playlistOptions = new DbContextOptionsBuilder <PlaylistContext>() .UseInMemoryDatabase("Rooms") .Options; RoomSong[] _roomSong = { new RoomSong() { Id = 1, RoomId = 1, SongId = 1, Song = _songs[0], }, new RoomSong() { Id = 2, RoomId = 1, SongId = 2, Song = _songs[1] } }; _playlistContext = new PlaylistContext(playlistOptions); _playlistContext.Database.EnsureDeleted(); if (_playlistContext.Database.EnsureCreated()) { _playlistContext.Tokens.Add(new Token() { JWTToken = _token, }); _playlistContext.Rooms.Add(new Room() { Id = 1, Name = "Room one", RoomSongs = new List <RoomSong>(_roomSong) }); _playlistContext.Rooms.Add(new Room() { Id = 2, Name = "Room Two", }); _playlistContext.Rooms.Add(new Room() { Id = 3, Name = "Room Three", }); _playlistContext.SaveChanges(); } }
public void TestInit() { var playlistOptions = new DbContextOptionsBuilder <PlaylistContext>() .UseInMemoryDatabase("Songs") .Options; _playlistContext = new PlaylistContext(playlistOptions); _playlistContext.Database.EnsureDeleted(); if (_playlistContext.Database.EnsureCreated()) { _playlistContext.Songs.Add(new Song() { Name = "New song", }); _playlistContext.SaveChanges(); } _songDataStore = new SongDataStore(_playlistContext); }
public void TestInit() { var playlistOptions = new DbContextOptionsBuilder <PlaylistContext>() .UseInMemoryDatabase("Rooms") .Options; _playlistContext = new PlaylistContext(playlistOptions); _playlistContext.Add(new Room() { Id = 1, Name = "Room one", }); _playlistContext.Add(new Room() { Id = 2, Name = "Room Two", }); _playlistContext.Add(new Room() { Id = 3, Name = "Room Three", }); _playlistContext.SaveChanges(); }
public IActionResult RequestForm(string songRequest, string email, string bandName, string bandLocation, bool GDPRConsent) { Visitor visitor = null; try { //validify all input if (HttpContext.Session.GetString("captcha") != "verified" || String.IsNullOrEmpty(HttpContext.Session.GetString("captcha"))) { return(BadRequest("Please verify that you are human")); } if (!Functions.Validify.IsValidEmail(email)) { return(BadRequest("Invalid email")); } if (String.IsNullOrEmpty(songRequest) || String.IsNullOrEmpty(bandName) || String.IsNullOrEmpty(bandLocation)) { return(BadRequest("Please fill up all form fields")); } if (!GDPRConsent) { return(BadRequest("You have to agree with our Privacy Policy")); } songRequest = HttpUtility.HtmlEncode(songRequest); bandName = HttpUtility.HtmlEncode(bandName); _context.Database.EnsureCreated(); visitor = EntityFW.InitializeVisitor(_context, _accessor); //Log Functions.Log.LogActivity(_context, "Index", "Sending form", visitor); //Check if band exists if not, create one Band band = _context.Band.Where(v => v.BandName == bandName).FirstOrDefault() ?? new Band { BandName = bandName, BandLocation = bandLocation }; User user = _context.User.Where(v => v.Email == email).FirstOrDefault() ?? new User { Email = email, ConsentGdpr = GDPRConsent }; UserHasVisitor UHV = _context.UserHasVisitor.Where(v => v.UserIdUserNavigation == user && v.VisitorIdVisitorNavigation == visitor).FirstOrDefault(); if (UHV == null) { UHV = new UserHasVisitor { UserIdUserNavigation = user, VisitorIdVisitorNavigation = visitor }; _context.UserHasVisitor.Add(UHV); } BandHasUser BHU = _context.BandHasUser.Where(v => v.UserIdUserNavigation == user && v.BandIdBandNavigation == band).FirstOrDefault(); if (BHU == null) { BHU = new BandHasUser { UserIdUserNavigation = user, BandIdBandNavigation = band }; _context.BandHasUser.Add(BHU); } //Create new song request SongRequest newSongRequest = new SongRequest { SongRequest1 = songRequest, IdUserNavigation = user }; _context.SongRequest.Add(newSongRequest); string[] songs = EntityFW.GetSongs(songRequest); foreach (string song in songs) { if (song.Contains("open.spotify.com") || song.Contains("youtube.com")) { _context.Song.Add(new Song { SongUrl = song, IdSongRequestNavigation = newSongRequest, IdBandNavigation = band }); } else { Functions.Log.LogError(_context, "Index-Send - Form - Invalid song url", song, visitor); } } try { Functions.Mail.SendMail("New song request", stringBuilder.Append("Band: ").Append(bandName).Append(" - From: ").Append(bandLocation).Append(" - Email: ").Append(email).Append("<br>Message:<br>").Append(songRequest).ToString()); } catch (Exception e) { Models.ErrorLog errorLog = new Models.ErrorLog(); errorLog.IdVisitorNavigation = visitor; errorLog.Message = e.Message; errorLog.Source = "Index-Send Form Email - " + e.Source; _context.ErrorLog.Add(errorLog); } _context.SaveChanges(); return(Ok("Thank you!")); } catch (Exception e) { Functions.Log.LogError(_context, "Index-Send Form", e.ToString(), visitor ?? EntityFW.InitializeVisitor(_context, _accessor)); return(BadRequest()); } }