Exemple #1
0
        public async Task <IActionResult> CreateSong(CreateSongModel model)
        {
            if (ModelState.IsValid)
            {
                SongData songData = new SongData();

                using (var memoryStream = new MemoryStream())
                {
                    await model.SongData.CopyToAsync(memoryStream);

                    songData.Data = memoryStream.ToArray();
                }

                bool result = await repository.CreateSongDataAsync(songData);

                if (result)
                {
                    Song song = new Song
                    {
                        SongName   = model.SongName,
                        TrackNum   = model.TrackNum,
                        AlbumId    = model.AlbumId,
                        SongDataId = songData.SongDataId,
                        VideoLink  = model.VideoLink
                    };
                    result = await repository.CreateSongAsync(song);

                    if (result)
                    {
                        return(RedirectToAction("CreateSong", "Create"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "An error occured while creating the Song");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "An error occured while creating the Song");
                }
            }
            return(View(model));
        }