From 83f63ad729d585d597bdcf0afc05b7d56344223e Mon Sep 17 00:00:00 2001 From: transtrike Date: Sun, 17 Jan 2021 13:38:24 +0200 Subject: Lang&Tech layers now return id on Create --- src/DevHive.Services/Services/PostService.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/DevHive.Services/Services/PostService.cs') diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 6e83ad4..f2f60d1 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -26,21 +26,35 @@ namespace DevHive.Services.Services } //Create - public async Task CreatePost(CreatePostServiceModel postServiceModel) + public async Task CreatePost(CreatePostServiceModel postServiceModel) { Post post = this._postMapper.Map(postServiceModel); - return await this._postRepository.AddAsync(post); + bool success = await this._postRepository.AddAsync(post); + + if(success) + { + Post newPost = await this._postRepository.GetPostByIssuerAndTimeCreatedAsync(postServiceModel.IssuerId, postServiceModel.TimeCreated); + return newPost.Id; + } + else + return Guid.Empty; } - public async Task AddComment(CreateCommentServiceModel commentServiceModel) + public async Task AddComment(CreateCommentServiceModel commentServiceModel) { commentServiceModel.TimeCreated = DateTime.Now; Comment comment = this._postMapper.Map(commentServiceModel); - bool result = await this._postRepository.AddCommentAsync(comment); + bool success = await this._postRepository.AddCommentAsync(comment); - return result; + if(success) + { + Comment newComment = await this._postRepository.GetCommentByIssuerAndTimeCreatedAsync(commentServiceModel.IssuerId, commentServiceModel.TimeCreated); + return newComment.Id; + } + else + return Guid.Empty; } //Read -- cgit v1.2.3