public async Task Update(int id, WidgetVariation model) { var widget = await _widgetsContext.WidgetVariations.FindAsync(id); if (widget == null) { return; } model.Id = 0; foreach (var item in model.Audiences) { item.Id = 0; } foreach (var state in model.States) { state.Id = 0; foreach (var container in state.WidgetContainers) { container.Id = 0; foreach (var component in container.WidgetComponents) { component.Id = 0; } } } _widgetsContext.Remove(widget); _widgetsContext.Add(model); await _widgetsContext.SaveChangesAsync(); }
public async Task <ActionResult <Widget> > CreateWidget([FromBody] Widget widget) { if (!ModelState.IsValid) { return(BadRequest()); } _context.Add(widget); await _context.SaveChangesAsync(); return(widget); }