public async Task <ViewCollection> CreateCollectionAsync([FromBody] CreateCollection createCollection) { var collection = createCollection.GetModel(); _context.Collections.Add(collection); await _context.SaveChangesAsync(); _logger.LogInformation($"Created collection #{collection.Id}."); return(ViewCollection.Create(collection)); }
public async Task <ViewCollection> AddFeedToCollection(Guid id, string feedId) { var collection = await _context.Collections.GetWithFeedsAsync(id); if (!collection.Feeds.ContainsId(feedId)) { var feed = await _context.Feeds.FindOrThrowAsync(feedId); collection.Feeds.Add(feed); await _context.SaveChangesAsync(); _logger.LogInformation($"Added feed \"{feed.Id}\" to collection #{collection.Id}."); } return(ViewCollection.Create(collection)); }
public async Task <ViewCollection> RemoveFeedFromCollectionAsync(Guid id, string feedId) { var collection = await _context.Collections.GetWithFeedsAsync(id); var feed = collection.Feeds.GetById(feedId); if (feed != null) { collection.Feeds.Remove(feed); await _context.SaveChangesAsync(); _logger.LogInformation($"Removed feed \"{feed.Id}\" from collection #{collection.Id}."); } return(ViewCollection.Create(collection)); }
public async Task <ViewCollection> GetCollectionAsync(Guid id) { var collection = await _context.Collections.GetWithFeedsAsync(id); return(ViewCollection.Create(collection)); }