public async Task <int> Add(SongPerformerDto input)
        {
            var songPerformers = new SongPerformer()
            {
                SongId      = input.SongId,
                PerformerId = input.PerformerId,
            };

            await this.repository.AddAsync(songPerformers);

            await this.repository.SaveChangesAsync();

            return(songPerformers.Id);
        }
Exemple #2
0
        public async Task <ActionResult <SongPerformerDto> > PostSongPerformer(SongPerformerDto songPerformer)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }
            if (!this.songsService.Exists((int)songPerformer.SongId) || !this.performerService.Exists((int)songPerformer.PerformerId))
            {
                return(this.BadRequest());
            }

            //return StatusCode((int)HttpStatusCode.Conflict);

            var id = await this.songsPerformersService.Add(songPerformer);

            songPerformer.Id = id;

            return(CreatedAtAction("GetSongPerformer", new { id = id }, songPerformer));
        }
        public async Task <bool> Update(int id, SongPerformerDto songPerformerDto)
        {
            var songPerformer = this.repository.All()
                                .Where(x => x.Id == id)
                                .FirstOrDefault();

            if (songPerformer == null)
            {
                return(false);
            }

            this.mapper.Map <SongPerformerDto, SongPerformer>(songPerformerDto, songPerformer);
            songPerformer.Id = id;


            this.repository.Update(songPerformer);
            await this.repository.SaveChangesAsync();

            return(true);
        }