public async Task <JsonResult> Create([FromBody] CommentCreateEditViewModel commentViewModel) { var userId = User.Claims.SingleOrDefault(a => a.Type == "UserId").Value; var newComment = await serviceOfComment.Create(userId, commentViewModel); return(Json(newComment)); }
public async Task <CommentViewModel> Create(string applicationUserIdCurrent, CommentCreateEditViewModel commentCreateEditViewModel) { var applicationUser = repositoryOfApplicationUser.Read(a => a.Id == applicationUserIdCurrent); if (await serviceOfUser.GetUserPriority(applicationUser) >= 1) { var commentEntity = mapper.Map <CommentCreateEditViewModel, CommentEntity>(commentCreateEditViewModel); commentEntity.UserProfileId = applicationUser.UserProfileId; commentEntity = repositoryOfComment.Create(commentEntity); var commentViewModel = GetViewModelWithProperty(nameof(CommentViewModel), commentEntity, applicationUserIdCurrent); return(commentViewModel as CommentViewModel); } return(null); }
public async Task <CommentViewModel> Update(string applicationUserIdCurrent, CommentCreateEditViewModel commentCreateEditViewModel) { var applicationUser = repositoryOfApplicationUser.Read(a => a.Id == applicationUserIdCurrent); if (await serviceOfUser.GetUserPriority(applicationUser) >= 1) { var commentEntity = mapper.Map <CommentCreateEditViewModel, CommentEntity>(commentCreateEditViewModel); repositoryOfComment.Update(commentEntity); commentEntity = repositoryOfComment.Read(a => a.Id == commentCreateEditViewModel.CommentId); var commentViewModel = mapper.Map <CommentEntity, CommentViewModel>(commentEntity); return(commentViewModel); } return(null); }