Exemple #1
0
 public void UpdateSong(Song song)
 {
     Song existingSong = context.Songs.First(s => s.SongId == song.SongId);
     existingSong.Artist = song.Artist;
     existingSong.Title = song.Title;
     existingSong.Description = song.Description;
     existingSong.Tags.Clear();
     context.Entry(existingSong).State = EntityState.Modified;
     context.SaveChanges();
     existingSong.Tags = song.Tags.Select(tag => GetOrCreateTag(tag.Name)).ToList();
     context.Entry(existingSong).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #2
0
 public void AddSong(Song song)
 {
     song.Tags = song.Tags.Select(tag => GetOrCreateTag(tag.Name)).ToList();
     context.Songs.Add(song);
     SaveChanges();
 }
        public JsonResult Upload(HttpPostedFileBase file)
        {
            byte[] fileBytes = FileUtils.ReadBytesFromStream(Request.InputStream);
            string fileName = string.Format("{0}.mp3", Guid.NewGuid());
            string path = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName);
            System.IO.File.WriteAllBytes(path, fileBytes);
            Id3Info info = Mp3Parser.GetMetaInfo(path);
            Song uploadedSong = new Song
            {
                Artist = info.Artist,
                Title = info.Title,
                Description = string.Format("{0} by {1} from album \"{2}\"", info.Title, info.Artist, info.Album),
                FilePath = path,
                Tags = new List<Tag> { new Tag { Name = info.Artist } }
            };
            repository.AddSong(uploadedSong);
            User uploader = repository.FindUserByName(User.Identity.Name);
            uploader.UploadInfos.Add(new UploadInfo { Date = DateTime.Now, Song = uploadedSong, User = uploader });
            repository.UpdateUser(uploader);

            return Json(new { id = uploadedSong.SongId });
        }