Example #1
0
        public MainViewModel()
        {
            MapperFactory.RegisterBsonMapper();

            var databaseService = new LiteDbRepository(new(typeof(EditModel), nameof(EditModel.Id)));
            var mapper          = MapperFactory.CreateMapperConfiguration().CreateMapper();

            if (databaseService.FindBy(new FirstOrDefaultQuery()) is { } editModel)
            {
                EditViewModel = mapper.Map <EditViewModel>(editModel);
            }

            EditViewModel
            .Changes(startWithSource: true)
            .Subscribe(a =>
            {
                EditModel = mapper.Map <EditModel>(a.source);
                databaseService.Upsert(EditModel);
                String = UtilityHelperEx.JsonHelper.Serialize(EditModel);
                this.RaisePropertyChanged(new(nameof(EditModel)));
                this.RaisePropertyChanged(new(nameof(String)));
            });
        }