Example #1
0
        public async Task <ILayoutUpdater> UpdateLayoutAsync(
            Func <LayoutViewModel, Task <LayoutViewModel> > configure)
        {
            // We always need a model to invoke configuration
            if (_model == null)
            {
                return(this);
            }

            // Configure model
            if (configure != null)
            {
                _model = await configure.Invoke(_model);
            }

            // Attempt to update controllers model to reflect configuration
            try
            {
                await _controller.TryUpdateModelAsync(_model);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
            }

            return(this);
        }
Example #2
0
        public Task <ILayoutUpdater> GetLayoutAsync(Controller controller)
        {
            _controller = controller;

            // Ensure our controller implements LayoutViewModel
            var model = _controller.ViewData.Model as LayoutViewModel;

            _model = model ?? null;

            return(Task.FromResult((ILayoutUpdater)this));
        }