BudgetAnalyser.Engine.Services.DashboardService.CreateNewBucketMonitorWidget C# (CSharp) Method

CreateNewBucketMonitorWidget() public method

Creates a new bucket monitor widget and adds it to the tracked widgetGroups collection. Duplicates are not allowed in the collection and will not be added.
public CreateNewBucketMonitorWidget ( string bucketCode ) : Widget
bucketCode string The bucket code to create a new monitor widget for.
return BudgetAnalyser.Engine.Widgets.Widget
        public Widget CreateNewBucketMonitorWidget(string bucketCode)
        {
            if (
                WidgetGroups.SelectMany(group => group.Widgets)
                    .OfType<BudgetBucketMonitorWidget>()
                    .Any(w => w.BucketCode == bucketCode))
            {
                // Bucket code already exists - so already has a bucket monitor widget.
                return null;
            }

            var widget = this.widgetService.Create(typeof(BudgetBucketMonitorWidget).FullName, bucketCode);
            return UpdateWidgetCollectionWithNewAddition((Widget) widget);
        }