1 Replies - 194 Views - Last Post: 05 February 2013 - 11:53 AM Rate Topic: -----

#1 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Mapping Save instead of If

Posted 05 February 2013 - 10:58 AM

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();
        }


Is This A Good Question/Topic? 0
  • +

Replies To: Mapping Save instead of If

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3247
  • View blog
  • Posts: 10,891
  • Joined: 12-December 12

Re: Mapping Save instead of If

Posted 05 February 2013 - 11:53 AM

Quote

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

Your code does not mention IDictionary at all.

Quote

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

Google or a book.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1