public override async Task <IActionResult> AddBuildToChannel(int channelId, int buildId) { Data.Models.Channel channel = await _context.Channels.FindAsync(channelId); if (channel == null) { return(NotFound(new ApiError($"The channel with id '{channelId}' was not found."))); } Build build = await _context.Builds.FindAsync(buildId); if (build == null) { return(NotFound(new ApiError($"The build with id '{buildId}' was not found."))); } // If build is already in channel, nothing to do if (build.BuildChannels != null && build.BuildChannels.Any(existingBuildChannels => existingBuildChannels.ChannelId == channelId)) { return(StatusCode((int)HttpStatusCode.Created)); } var buildChannel = new BuildChannel { Channel = channel, Build = build, DateTimeAdded = DateTimeOffset.UtcNow }; await _context.BuildChannels.AddAsync(buildChannel); await _context.SaveChangesAsync(); return(StatusCode((int)HttpStatusCode.Created)); }
public override async Task <IActionResult> DeleteChannel(int id) { Data.Models.Channel channel = await _context.Channels .Include(ch => ch.ChannelReleasePipelines) .FirstOrDefaultAsync(c => c.Id == id); if (channel == null) { return(NotFound()); } // Ensure that there are no subscriptions associated with the channel if (await _context.Subscriptions.AnyAsync(s => s.ChannelId == id)) { return(BadRequest( new ApiError($"The channel with id '{id}' has associated subscriptions. " + "Please remove these before removing this channel."))); } if (channel.ChannelReleasePipelines != null && channel.ChannelReleasePipelines.Any()) { return(BadRequest( new ApiError($"The channel with id '{id}' has '{channel.ChannelReleasePipelines.Count()}' " + $"release pipeline(s) attached to it. Detach those release pipelines(s) first."))); } _context.Channels.Remove(channel); await _context.SaveChangesAsync(); return(Ok(new Channel(channel))); }
public override async Task <IActionResult> GetChannel(int id) { Data.Models.Channel channel = await _context.Channels .Where(c => c.Id == id).FirstOrDefaultAsync(); if (channel == null) { return(NotFound()); } return(Ok(new Channel(channel))); }
public override async Task <IActionResult> GetChannel(int id) { Data.Models.Channel channel = await _context.Channels .Include(ch => ch.ChannelReleasePipelines) .ThenInclude(crp => crp.ReleasePipeline) .Where(c => c.Id == id).FirstOrDefaultAsync(); if (channel == null) { return(NotFound()); } return(Ok(new Channel(channel))); }
public override async Task <IActionResult> CreateChannel([Required] string name, [Required] string classification) { var channelModel = new Data.Models.Channel { Name = name, Classification = classification }; await _context.Channels.AddAsync(channelModel); await _context.SaveChangesAsync(); return(CreatedAtRoute( new { action = "GetChannel", id = channelModel.Id }, new Channel(channelModel))); }
public override async Task <IActionResult> DeleteChannel(int id) { Data.Models.Channel channel = await _context.Channels .FirstOrDefaultAsync(c => c.Id == id); if (channel == null) { return(NotFound()); } // Ensure that there are no subscriptions associated with the channel if (await _context.Subscriptions.AnyAsync(s => s.ChannelId == id)) { return(BadRequest( new ApiError($"The channel with id '{id}' has associated subscriptions. " + "Please remove these before removing this channel."))); } _context.Channels.Remove(channel); await _context.SaveChangesAsync(); return(Ok(new Channel(channel))); }