public async Task <UserYouTubeChannelModel> AddUserYouTubeChannel(UserYouTubeChannelModel userYouTubeChannelModel, CancellationToken cancellationToken) { var entity = await this.UserYouTubeChannelService.AddUserYouTubeChannelAsync(userYouTubeChannelModel, cancellationToken); return(this.Mapper.Map <UserYouTubeChannel, UserYouTubeChannelModel>(entity)); }
public async Task <UserYouTubeChannel> AddUserYouTubeChannelAsync(UserYouTubeChannelModel userYouTubeChannelModel, CancellationToken cancellationToken) { var entity = await this.FairplaytubeDatabaseContext.UserYouTubeChannel .SingleOrDefaultAsync(p => p.ApplicationUserId == userYouTubeChannelModel.ApplicationUserId && p.YouTubeChannelId == userYouTubeChannelModel.YouTubeChannelId, cancellationToken : cancellationToken); if (entity is not null) { throw new CustomValidationException($"User {userYouTubeChannelModel.ApplicationUserId} has already added Channel: {userYouTubeChannelModel.YouTubeChannelId}"); } entity = new DataAccess.Models.UserYouTubeChannel() { ApplicationUserId = userYouTubeChannelModel.ApplicationUserId, YouTubeChannelId = userYouTubeChannelModel.YouTubeChannelId }; await this.FairplaytubeDatabaseContext.UserYouTubeChannel.AddAsync(entity, cancellationToken : cancellationToken); await this.FairplaytubeDatabaseContext.SaveChangesAsync(cancellationToken : cancellationToken); return(entity); }