public async Task <SubsetGroup> Create(SubsetGroup subsetGroup) { var sqlSubset = new Models.Subset { Name = subsetGroup.Name }; var sqlSubsetItems = subsetGroup.Items.Select(i => new Models.SubsetItem { ItemId = i.ItemId, Subset = sqlSubset }); await Context.Subsets.AddAsync(sqlSubset); await Context.SubsetItems.AddRangeAsync(sqlSubsetItems); await Context.SaveChangesAsync(); return(new SubsetGroup { SubsetId = sqlSubset.SubsetId, Name = sqlSubset.Name, Items = subsetGroup.Items }); }
public async Task <SubsetGroup> Update(SubsetGroup subsetGroup) { var sqlSubset = await Context.Subsets.SingleAsync(s => s.SubsetId == subsetGroup.SubsetId); sqlSubset.Name = subsetGroup.Name; var currSqlSubsetItems = await Context.SubsetItems.Where(i => i.SubsetId == subsetGroup.SubsetId).ToListAsync(); Context.RemoveRange(currSqlSubsetItems); var sqlSubsetItems = subsetGroup.Items.Select(i => new Models.SubsetItem { ItemId = i.ItemId, Subset = sqlSubset }); await Context.SubsetItems.AddRangeAsync(sqlSubsetItems); await Context.SaveChangesAsync(); return(subsetGroup); }