public async Task <IActionResult> Create([Bind("Id,Title,Artist,ReleaseDate,Genre,ImagePath,Price")] Song song, IFormFile file) { long size = file.Length; var path = @"\Content\Images\NoAlbumImage.png"; if (size > 0) { var fileName = Path.GetFileName(file.FileName); path = _env.WebRootPath + "\\uploads\\albums\\" + fileName; using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } //update song path song.ImagePath = "uploads/albums/" + fileName; } if (ModelState.IsValid) { _songsRepo.AddSong(song); _songsRepo.Save(); return(RedirectToAction(nameof(Index))); } return(View(song)); }
protected override void Seed(TestRockstars.DAL.DatabaseContext context) { JSONParser parse = new JSONParser(); SongsRepository songRepository = new SongsRepository(context); ArtistsRepository artistRepository = new ArtistsRepository(context); artistRepository.ClearArtists(); songRepository.ClearSongs(); songRepository.AddSong(parse.GetSongs().ToArray()); artistRepository.AddArtist(parse.GetArtists().ToArray()); }
public void AddSong() { var mockSet = new Mock <DbSet <Song> >(); var mockContext = new Mock <DatabaseContext>(); mockContext.Setup(m => m.Songs).Returns(mockSet.Object); var service = new SongsRepository(mockContext.Object); service.AddSong(testSong); mockSet.Verify(m => m.Add(testSong), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public async Task <IHttpActionResult> PostSong(Song song) { if (dbRepository.GetSongs().Where(a => a.Name.Equals(song.Name)).Count() > 0) { return(BadRequest("That name already exists!")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } dbRepository.AddSong(song); await dbRepository.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = song.Id }, song)); }