/// <summary> /// Get all campaigns (eventually with filtering options) /// </summary> /// <returns>Returns a list of campaigns. If none exist, an empty array is returned. If an error occurs, an exception is thrown</returns> public async Task <IEnumerable <Dnd35Campaign> > GetCampaignsAsync() { using (var db = new Dnd35DataContext()) { return(await db.Campaigns.ToListAsync()); } }
/// <summary> /// Adds a campaign with the given campaign name and GM's userId to the database /// </summary> /// <param name="name">The name of the campaign</param> /// <param name="userId">The GM's userId address (uniquely identifies the GM)</param> /// <returns>The ID of the added campaign</returns> public async Task <Guid> AddCampaignAsync(string name, string userId) { using (var db = new Dnd35DataContext()) { var campaign = new Dnd35Campaign { Name = name, GmUserId = userId }; db.Campaigns.Add(campaign); int changes = await db.SaveChangesAsync(); if (changes != 1) { throw new Exception("Could not save campaign"); } return(campaign.CampaignId); } }