Exemple #1
0
        public async Task <IActionResult> AddMusicType(int userid, int musicid)
        {
            /*if(userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
             *  return Unauthorized();
             */
            var music = await _repo.GetMusicType(musicid);

            if (music == null)
            {
                return(BadRequest("There is not a music type"));
            }

            var account_music = await _repo.AccountMusic(userid, musicid);

            if (account_music != null)
            {
                return(BadRequest("It is already added"));
            }

            Music_type_account mta = new Music_type_account();

            mta.Account_Id    = userid;
            mta.Music_type_id = musicid;
            _repo.Add(mta);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Adding music preference failed on save");
        }