示例#1
0
        public async Task <ActionResult> CreatePost(PostViewModel newPost)
        {
            var currentUserName = System.Web.HttpContext.Current.User.Identity.Name;
            var userVm          = new UserViewModel {
                UserName = currentUserName
            };

            newPost.User = userVm;
            await service.CreatePostAsync(newPost.ToDto());

            return(RedirectToAction(Constant.View.Index, Constant.View.Post));
        }
示例#2
0
        public async Task <IActionResult> SavePost([FromBody] PostViewModel model)
        {
            var dto = model.ToDto();
            var id  = await _postDataService.Upsert(dto);

            if (!string.IsNullOrWhiteSpace(id))
            {
                var newDto = await _postDataService.Get(id);

                var result = new PostViewModel(newDto);

                return(Json(ApiResponseViewModel.Success(result)));
            }
            else
            {
                return(Json(ApiResponseViewModel.Failed()));
            }
        }
示例#3
0
        public async Task <ActionResult> ChangePost(PostViewModel post)
        {
            await service.ModifyPostAsync(post.Id, post.ToDto());

            return(RedirectToAction(Constant.View.GetPost, new { postId = post.Id }));
        }