コード例 #1
0
        public async Task <CommentModel> UpdateCommentAsync(int id, Comment comment)
        {
            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new AppException($"Unable to perform update operation. Error occurerd : {e.Message}");
            }

            User user = await _context.Users.FindAsync(comment.UserId);

            return(new CommentModel {
                Content = comment.Content,
                Id = comment.Id,
                Username = user.Username,
            });
        }
コード例 #2
0
ファイル: PostService.cs プロジェクト: akashmanoj213/dwitter
        public async Task <PostModel> UpdatePostAsync(int id, Post post)
        {
            _context.Entry(post).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new AppException($"Unable to perform update operation. Error occurerd : {e.Message}");
            }

            User user = await _context.Users.FindAsync(post.UserId);

            return(new PostModel {
                Content = post.Content,
                Id = post.Id,
                Likes = post.Likes,
                UserId = user.Id,
                Username = user.Username
            });
        }