コード例 #1
0
        public async Task <ActionResult> Save(PostEditorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await _postsServicio.UpdatePost(viewModel.ToPostEditorDto());
            }

            return(Content(string.Empty));
        }
コード例 #2
0
        public async Task <ActionResult> Edit(PostEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var updatePostResult = await _postsServicio.UpdatePost(viewModel.ToPostEditorDto());

            if (updatePostResult.IsFailure)
            {
                ModelState.AddModelError("*", updatePostResult.Error);
            }

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <ActionResult> Create(string boton, PostEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var createPostResult = await _postsServicio.CreatePost(viewModel.ToPostEditorDto());

            if (createPostResult.IsFailure)
            {
                ModelState.AddModelError("*", createPostResult.Error);
            }

            if (boton.ToLower().Contains(@"exit"))
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Edit", new { viewModel.Id }));
        }