Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Mapping Save instead of If

$
0
0
Trying to use an IDictionary to save the result instead of the if statements below.

What's the best way to go about implementing a dictionary with code examples? Thanks

public SaveResult Save(PageBuilderViewModel pageBuilderViewModel)
        {
            var cmsPage = GetPage();

            foreach (var region in pageBuilderViewModel.Regions)
	        {
                var dbRegion = cmsPage.WidgetsByRegion.FirstOrDefault(x => x.Key == region.Name);
                var dbWidgets = dbRegion.Value;
                dbWidgets.Clear();

                foreach (var widget in region.Widgets)
                {
                    // TODO: need a widget factory
                    if (widget.Name == "HTML")
                    {
                        dbWidgets.Add(new HtmlWidget(widget.Value));
                    }
                    if (widget.Name == "DateTime")
                    {
                        dbWidgets.Add(new DateTimeWidget());
                    }
                }
	        }
            _documentSession.SaveChanges();

            // TODO: add save infos
            return new SaveResult();
        }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>