Beispiel #1
0
        public async Task <IActionResult> SaveSong(int userId, int songId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var savedSong = await _repo.GetSavedSong(userId, songId);

            if (savedSong != null)
            {
                return(BadRequest("You already saved this song"));
            }

            if (await _repo.GetSong(songId) == null)
            {
                return(NotFound());
            }

            savedSong = new SavedSong
            {
                UserId = userId,
                SongId = songId
            };

            _repo.Add <SavedSong>(savedSong);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to save song"));
        }
        public async Task <IActionResult> CreateRecommendation(RecommendationDto recommendation)
        {
            var recommendationToCreate = _mapper.Map <Recommendation>(recommendation);

            _repo.Add(recommendationToCreate);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Filed to Create Recommendation"));
        }