示例#1
0
        public async Task <ActionResult <Song> > CreateSong(SongCreateViewModel model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var result = await _songService.AddSong(_mapper.Map <SongDTO>(model), user);

            return(result.Succeeded ? (ActionResult)Ok(result.Model) : BadRequest(result.Error));
        }
        public async Task <ActionResult <Song> > PostSong(SongCreateViewModel scvw)
        {
            Song newSong = new Song
            {
                Title  = scvw.Title,
                Lyrics = scvw.Lyrics,
                UserId = HttpContext.GetUserId()
            };

            _context.Songs.Add(newSong);
            await _context.SaveChangesAsync();

            var foundSong = _context.Songs.Where(s => s.UserId == newSong.UserId).OrderByDescending(s => s.Id).Take(1);

            return(Ok(foundSong));
        }
示例#3
0
        private string ProcessUploadedFile(SongCreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
                model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
            }

            return(uniqueFileName);
        }
示例#4
0
        //Zet het pad van het nieuw toegevoegde nummer in de database
        public SongCreateViewModel AddNewSong(SongCreateViewModel songCreateViewModel)
        {
            SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[Song] (Name, SongLink, GenreID, ArtistID, AlbumID) values (@NameSong , @SongPath, @Genre, @Artist, @Album)", con);

            cmd.Parameters.AddWithValue("@NameSong", songCreateViewModel.Name);
            cmd.Parameters.AddWithValue("@SongPath", songCreateViewModel.SongLink);
            cmd.Parameters.AddWithValue("@Genre", AddGenreID(songCreateViewModel));
            cmd.Parameters.AddWithValue("@Artist", AddArtistID(songCreateViewModel));
            cmd.Parameters.AddWithValue("@Album", AddAlbumID(songCreateViewModel));

            con.Open();

            cmd.ExecuteNonQuery();

            con.Close();

            return(songCreateViewModel);
        }
示例#5
0
        public IActionResult UploadMusic(SongCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);

                Song newSong = new Song
                {
                    Artist    = model.Artist,
                    SongName  = model.SongName,
                    License   = model.License,
                    PhotoPath = uniqueFileName
                };

                _songRepository.Add(newSong);
                return(RedirectToAction("Details", new { id = newSong.Id }));
            }

            return(View());
        }
示例#6
0
        public int AddArtistID(SongCreateViewModel songCreateViewModel)
        {
            int ArtistID = 0;

            SqlCommand cmd  = new SqlCommand(@"insert into Artist (ArtistName)
                                            Select @Name Where not exists(select * from Artist where ArtistName = @Name)", con);
            SqlCommand read = new SqlCommand(@"SELECT * FROM [Artist] WHERE ArtistName = @Name", con);

            cmd.Parameters.AddWithValue("@Name", songCreateViewModel.Artist);
            read.Parameters.AddWithValue("@Name", songCreateViewModel.Artist);
            con.Open();
            cmd.ExecuteNonQuery();
            SqlDataReader reader = read.ExecuteReader();

            while (reader.Read())
            {
                ArtistID = Convert.ToInt32((reader["ID"].ToString()));
            }
            con.Close();
            return(ArtistID);
        }
示例#7
0
        public int AddGenreID(SongCreateViewModel songCreateViewModel)
        {
            int GenreID = 0;

            SqlCommand read = new SqlCommand(@"SELECT * FROM [Genre] WHERE GenreName = @Name", con);

            read.Parameters.AddWithValue("@Name", songCreateViewModel.Genre);

            con.Open();

            SqlDataReader reader = read.ExecuteReader();

            while (reader.Read())
            {
                GenreID = Convert.ToInt32((reader["ID"].ToString()));
            }

            con.Close();

            return(GenreID);
        }
        public async Task <IActionResult> Create(SongCreateViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            DotNetEnv.Env.Load();

            var songToDb = new Song
            {
                Title           = vm.SongTitle,
                NormalizedTitle = vm.SongTitle.ToUpper(),
                Duration        = vm.Duration,
                SongLink        = vm.Link.Replace(DotNetEnv.Env.GetString("YOUTUBE_LINK"), "")
            };

            await _songService.ChangeAlbum(vm.AlbumTitle, songToDb);

            if (songToDb.Album != null && songToDb.Album.ReleaseDate == null && vm.ReleaseDate.HasValue)
            {
                songToDb.Album.ReleaseDate = vm.ReleaseDate.Value;
            }

            if (vm.PhotoUrl != null && songToDb.Album != null)
            {
                songToDb.Album.PhotoUrl = _photoService.AddPhoto(vm.PhotoUrl);
            }

            await _songService.ChangeBand(vm.BandName, songToDb);

            await _applicationDbContext.Songs.AddAsync(songToDb);

            await _applicationDbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public IActionResult Upload(SongCreateViewModel model)
        {
            ViewBag.User = currentAdmin;

            if (ModelState.IsValid)
            {
                if (model.Song != null)
                {
                    string UploadsFolder = Path.Combine(hostingEnviroment.WebRootPath, "Music");
                    model.SongLink = Guid.NewGuid().ToString() + "_" + model.Song.FileName;

                    string filePath = Path.Combine(UploadsFolder, model.SongLink);
                    model.Song.CopyTo(new FileStream(filePath, FileMode.Create));

                    songContainer.NewSongAdd(model);
                }
                else
                {
                    ViewBag.SuccesOrNot = "Could not save song!";
                }
            }
            ViewBag.SuccesOrNot = "Song saved!";
            return(View("Admin"));
        }
示例#10
0
        public async Task <ActionResult <Song> > CreateSong(SongCreateViewModel model)
        {
            var result = await _songService.AddSong(_mapper.Map <SongDTO>(model));

            return(result.Succeeded ? (ActionResult)Ok(result.Model) : BadRequest(result.Error));
        }