Beispiel #1
0
        public void AddSong(UploadSongBindingModel model,
                            string audioFileName, string coverFileName)
        {
            Song song = Mapper.Instance.Map <UploadSongBindingModel, Song>(model);

            song.Uploader      = context.Users.Find(HttpContext.Current.User.Identity.GetUserId());
            song.AudioFileName = audioFileName;
            song.ImageFileName = coverFileName;
            song.UploadDate    = DateTime.Now;
            song.Genre         = this.context.Genres.Find(model.GenreId);

            context.Songs.Add(song);
            context.SaveChanges();
        }
Beispiel #2
0
        public ActionResult Upload(UploadSongBindingModel model)
        {
            if (model.AudioFile.ContentType.Contains("audio") &&
                model.AudioFile.ContentLength > 0)
            {
                var    audioPath     = Server.MapPath("~/uploads/audio/");
                var    imagePath     = Server.MapPath("~/uploads/image/");
                string audioFileName = service.UploadAudioFile(model.AudioFile, audioPath);
                string coverFileName = service.UploadCoverFile(model.ImageFile, imagePath);

                service.AddSong(model, audioFileName, coverFileName);

                return(RedirectToAction("Index"));
            }

            ViewBag.Genres = service.GetAvailableGenres();
            return(View(model));
        }