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> > DeleteWidget(int id) { if (id < 1) { return(BadRequest()); } var oldWidget = await _context.Widgets.FindAsync(id); if (oldWidget == null) { return(NotFound()); } _context.Remove(oldWidget); await _context.SaveChangesAsync(); return(oldWidget); }