Source

TrafficLight / src / Core / Presenters / SettingsPresenter.cs

Full commit
using RossCode.TrafficLight.Core.Domain.Repositories;
using RossCode.TrafficLight.Core.Eventing;
using RossCode.TrafficLight.Core.Eventing.Events;
using RossCode.TrafficLight.Core.Presenters.Views;

namespace RossCode.TrafficLight.Core.Presenters
{
    public class SettingsPresenter : PresenterBase<ISettingsView>
    {
        private readonly IIndicatorTypeRepository indicatorTypeRepository;

        public SettingsPresenter(ISettingsView view, IIndicatorTypeRepository indicatorTypeRepository) : base(view)
        {
            this.indicatorTypeRepository = indicatorTypeRepository;
            View.Load += (sender, args) => LoadConfiguration();
            view.SaveClicked += SaveConfiguration;
        }

        private void SaveConfiguration()
        {
            indicatorTypeRepository.EnableIndicators(View.GetIndicatoryTypes());
            View.Close();
            DomainEvents.Raise(new IndicatorsChanged());
        }

        private void LoadConfiguration()
        {
            View.SetSelectedProjectsTo(indicatorTypeRepository.GetAll());
        }
    }
}