예제 #1
0
        public ActionResult DeleteSong(int id)
        {
            Request.Headers.TryGetValue("email", out var emailValue);
            Request.Headers.TryGetValue("UserName", out var userID);

            if (_repository.GetUserById(userID) == null)
            {
                if (userID != "")
                {
                    var user = new UserCreate();
                    user.name  = userID;
                    user.email = emailValue;
                    var userModel = _mapper.Map <UserData>(user);
                    _repository.CreateUser(userModel);
                    _repository.SaveChanges();
                }
                else
                {
                    return(Unauthorized("Invalid user"));
                }
            }

            var songItem = _repository.GetSongById(id);

            if (songItem != null)
            {
                _repository.DeleteSong(songItem);
                _repository.SaveChanges();
                return(NoContent());
            }
            else
            {
                return(NotFound());
            }
        }