Ejemplo n.º 1
0
        public IActionResult Create(CreateDocumentViewModel vm)
        {
            var presenter = _presenterFactory.Create(MessageHandler, ErrorHandler);

            if (!ModelState.IsValid)
            {
                return(View(presenter.Present(vm)));
            }

            var request = vm.ToRequest(CurrentUserId);

            try
            {
                var uc       = _useCaseFactory.Create;
                var response = uc.Execute(request);
                return(RedirectToAction(nameof(Index), new { id = presenter.Present(response) }));
            }
            catch (InvalidRequestException ire)
            {
                presenter.PresentErrors(ire.Message, ire.Errors);
                return(View(presenter.Present(vm)));
            }
            catch (Exception e)
            {
                presenter.PresentMessage(MessageType.Error, e.Message);
                return(View(presenter.Present(vm)));
            }
        }