public async Task <AddWidgetResponse> AddWidgetToTabAsync(string tabId, string widgetId) { var result = new AddWidgetResponse { Success = false }; var layout = await _context.GetLayoutForTabAsync(tabId); if (layout == null) { return(result); } var fullWidget = await _context.GetWidgetAsync(widgetId); var firstLayoutRow = layout.LayoutRows.OrderBy(e => e.RowIndex).FirstOrDefault(); var placement = new WidgetPlacement { Collapsed = false, LayoutRowId = firstLayoutRow.LayoutRowId, ColumnIndex = 0, WidgetId = widgetId, Widget = fullWidget, UseTemplate = fullWidget.UseTemplate, UseSettings = fullWidget.UseSettings, WidgetIndex = firstLayoutRow.WidgetPlacements.Count + 1, WidgetSettings = fullWidget.WidgetDefaults.Select(def => new WidgetSetting { Value = def.DefaultValue, WidgetDefaultId = def.WidgetDefaultId, WidgetDefault = def }).ToList() }; await _context.WidgetPlacement.AddAsync(placement); result.Success = await _context.SaveChangesAsync(new CancellationToken()) > 0; result.PlacementId = placement.WidgetPlacementId; return(result); }
public AddWidgetResponse AddWidgetToTab(string tabId, string widgetId) { var result = new AddWidgetResponse { Success = false }; var layout = _context.GetLayoutForTab(tabId); if (layout == null) { return(result); } var widget = _context.GetWidget(widgetId); var firstLayoutRow = layout.LayoutRows.OrderBy(e => e.RowIndex).FirstOrDefault(); var placement = new WidgetPlacement { Collapsed = false, LayoutRowId = firstLayoutRow.LayoutRowId, ColumnIndex = 0, WidgetId = widgetId, Widget = widget, UseTemplate = widget.UseTemplate, UseSettings = widget.UseSettings, WidgetIndex = firstLayoutRow.WidgetPlacements.Count + 1, WidgetSettings = widget.WidgetDefaults.Select(def => new WidgetSetting { Value = def.DefaultValue, WidgetDefaultId = def.WidgetDefaultId, WidgetDefault = def }).ToList() }; _context.WidgetPlacement.Add(placement); result.Success = _context.SaveChanges() > 0; result.PlacementId = placement.WidgetPlacementId; return(result); }