CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Example Presenter (ViewModel) showing db4o interactions

229 Views
Copy Code Show/Hide Line Numbers
using System.Collections.Generic;
using System.Linq;
using Caliburn.PresentationFramework.ApplicationModel;
using CWS.Application.Rounds.Model;
using Db4objects.Db4o;
 
namespace CWS.Application.Rounds.Presenters
{
    public class SectionPresenter : Presenter, ISectionPresenter
    {
        private readonly IObjectContainer _objectContainer;
        private IList<EquipmentData> _equipmentData;
 
        public Sheet CurrentSheet { get; set; }
        public Section CurrentSection { get; set; }
 
        public SectionPresenter(IObjectContainer objectContainer)
        {
            _objectContainer = objectContainer;
        }
 
        protected override void OnInitialize()
        {
            base.OnInitialize();
 
            _equipmentData = _objectContainer.Query<EquipmentData>(
                x =>
                    x.Equipment.Section == CurrentSection &&
                    x.Sheet == CurrentSheet).OrderBy(x => x.Equipment.Order).ToList();
        }
 
        protected override void OnShutdown()
        {
            var sectionEquipmentData =
                from ed in CurrentSheet.EquipmentData
                where ed.Equipment.Section == CurrentSection
                select ed;
 
            sectionEquipmentData.Run(x => _objectContainer.Store(x));
 
            _objectContainer.Store(CurrentSheet);
 
            base.OnShutdown();
        }
 
        public IList<EquipmentData> EquipmentData
        {
            get { return _equipmentData; }
        }
    }
}
by Andy Sherwood
  February 01, 2010 @ 7:02pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate