From 5307c3943f9db6bbd50121e8ece091dff21c993d Mon Sep 17 00:00:00 2001
From: Lucca Santangelo <luccasant95@gmail.com>
Date: Sat, 28 Nov 2020 13:35:15 -0300
Subject: [PATCH] ids in creates endpoints

---
 .../Tsi1.Api/Controllers/CommunicationController.cs    |  4 ++--
 Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs      |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs       |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/PostController.cs        |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/PostMessageController.cs |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/SectionController.cs     |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/SectionItemController.cs |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs      |  2 +-
 Tsi1.Api/Tsi1.Api/Controllers/UserController.cs        |  2 +-
 .../Interfaces/ICommunicationService.cs                |  2 +-
 .../Tsi1.BusinessLayer/Interfaces/IForumService.cs     |  2 +-
 .../Interfaces/IPostMessageService.cs                  |  2 +-
 Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostService.cs |  2 +-
 .../Tsi1.BusinessLayer/Interfaces/ISurveyService.cs    |  2 +-
 Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs |  2 +-
 .../Services/CommunicationService.cs                   | 10 +++++-----
 Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs  |  1 +
 Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs   |  6 +++---
 .../Tsi1.BusinessLayer/Services/PostMessageService.cs  |  6 +++---
 Tsi1.Api/Tsi1.BusinessLayer/Services/PostService.cs    |  7 +++----
 .../Tsi1.BusinessLayer/Services/SectionItemService.cs  |  1 +
 Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs  |  8 ++++----
 Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs    |  6 +++---
 23 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs
index 479c0d7..41247ae 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs
@@ -42,7 +42,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
@@ -63,7 +63,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.FacultyAdmin)]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
index 9097c57..3778365 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
@@ -51,7 +51,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
 
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs b/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
index 83a96c4..09b35e9 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
@@ -47,7 +47,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.Professor)]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
index 720f6cd..a20d5fc 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
@@ -71,7 +71,7 @@ namespace Tsi1.Api.Controllers
                 }
             }
             
-            return Ok(result.Data.Id);
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/PostMessageController.cs b/Tsi1.Api/Tsi1.Api/Controllers/PostMessageController.cs
index cf2cbb9..0812fdc 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/PostMessageController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/PostMessageController.cs
@@ -51,7 +51,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/SectionController.cs b/Tsi1.Api/Tsi1.Api/Controllers/SectionController.cs
index 81946f2..487e465 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/SectionController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/SectionController.cs
@@ -29,7 +29,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [HttpPut("Modify/{sectionId}")]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/SectionItemController.cs b/Tsi1.Api/Tsi1.Api/Controllers/SectionItemController.cs
index 04e043b..42ec203 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/SectionItemController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/SectionItemController.cs
@@ -34,7 +34,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [HttpDelete("Delete/{sectionItemId}")]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs b/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs
index 990851a..3914c15 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs
@@ -42,7 +42,7 @@ namespace Tsi1.Api.Controllers
                 return BadRequest(result.Message);
             }
 
-            return Ok();
+            return Ok(result.Data);
         }
 
         [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs
index e0ffd0b..eee69b7 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs
@@ -159,7 +159,7 @@ namespace Tsi1.Api.Controllers
                 BadRequest(userServiceResult.Message);
             }
 
-            return Ok();
+            return Ok(userServiceResult.Data);
         }
 
         [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs
index 0c14aae..d4a6245 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs
@@ -9,7 +9,7 @@ namespace Tsi1.BusinessLayer.Interfaces
 {
     public interface ICommunicationService
     {
-        Task<ServiceResult<bool>> Create(CommunicationCreateDto newCommunication, int id);
+        Task<ServiceResult<int>> Create(CommunicationCreateDto newCommunication, int id);
 
         Task<ServiceResult<bool>> Delete(int communicationId);
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IForumService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IForumService.cs
index db95e50..2e4e4c8 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IForumService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IForumService.cs
@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
     {
         Task<ServiceResult<List<ForumPreviewDto>>> GetForums(int sectionId);
 
-        Task<ServiceResult<Forum>> Create(ForumCreateDto newForum);
+        Task<ServiceResult<int>> Create(ForumCreateDto newForum);
 
         Task<ServiceResult<Forum>> Delete(int forumId);
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostMessageService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostMessageService.cs
index a1b34f4..6d3ddcc 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostMessageService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostMessageService.cs
@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
     {
         Task<ServiceResult<List<PostMessagePreviewDto>>> GetPostMessages(int postId);
 
-        Task<ServiceResult<PostMessage>> Create(PostMessageCreateDto newPostMessage);
+        Task<ServiceResult<int>> Create(PostMessageCreateDto newPostMessage);
 
         Task<ServiceResult<PostMessage>> Delete(int postMessageId);
     }
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostService.cs
index 40dbc56..d73acc2 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IPostService.cs
@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
     {
         Task<ServiceResult<List<PostPreviewDto>>> GetPosts(int forumId);
 
-        Task<ServiceResult<Post>> Create(PostCreateDto newPost);
+        Task<ServiceResult<int>> Create(PostCreateDto newPost);
 
         Task<ServiceResult<Post>> Delete(int postId);
     }
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs
index b521e5a..6ec00d5 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs
@@ -9,7 +9,7 @@ namespace Tsi1.BusinessLayer.Interfaces
 {
     public interface ISurveyService
     {
-        Task<ServiceResult<bool>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId);
+        Task<ServiceResult<int>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId);
         Task<ServiceResult<bool>> DeleteGlobalSurvey(int surveyId, string userType, int tenantId);
         Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId, string userType);
         Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId);
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs
index d503323..1fa9902 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs
@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
     {
         Task<ServiceResult<User>> Authenticate(string username, string password, int tenantId);
 
-        Task<ServiceResult<User>> Create(UserRegisterDto dto, string type, int tenantId);
+        Task<ServiceResult<int>> Create(UserRegisterDto dto, string type, int tenantId);
 
         Task<ServiceResult<List<UserDetailDto>>> GetAll(int tenantId);
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs
index ffcd09d..1a608b1 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs
@@ -24,9 +24,9 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<bool>> Create(CommunicationCreateDto newCommunication, int id)
+        public async Task<ServiceResult<int>> Create(CommunicationCreateDto newCommunication, int id)
         {
-            var result = new ServiceResult<bool>();
+            var result = new ServiceResult<int>();
             var isGlobal = newCommunication.IsGlobal;
             var commmunication = _mapper.Map<Communication>(newCommunication);
 
@@ -38,9 +38,9 @@ namespace Tsi1.BusinessLayer.Services
             }
 
             _context.Communications.Add(commmunication);
-
             await _context.SaveChangesAsync();
 
+            result.Data = commmunication.Id;
             return result;
         }
 
@@ -206,9 +206,9 @@ namespace Tsi1.BusinessLayer.Services
             return result;
         }
 
-        private async Task<ServiceResult<bool>> CreateValidation(int id, bool isGlobal, Communication commmunication)
+        private async Task<ServiceResult<int>> CreateValidation(int id, bool isGlobal, Communication commmunication)
         {
-            var result = new ServiceResult<bool>();
+            var result = new ServiceResult<int>();
 
             if (isGlobal)
             {
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs
index cd9387a..bc1eeb8 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs
@@ -52,6 +52,7 @@ namespace Tsi1.BusinessLayer.Services
             _context.Courses.Add(course);
             await _context.SaveChangesAsync();
 
+            result.Data = course.Id;
             return result;
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
index 6418cd5..71c5bde 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
@@ -26,15 +26,15 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<Forum>> Create(ForumCreateDto newForum)
+        public async Task<ServiceResult<int>> Create(ForumCreateDto newForum)
         {
-            var result = new ServiceResult<Forum>();
+            var result = new ServiceResult<int>();
             var forum = _mapper.Map<Forum>(newForum);
 
             _context.Forums.Add(forum);
             await _context.SaveChangesAsync();
    
-            result.Data = forum;
+            result.Data = forum.Id;
             return result;
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/PostMessageService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/PostMessageService.cs
index 7d7431f..1868f2e 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/PostMessageService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/PostMessageService.cs
@@ -25,9 +25,9 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<PostMessage>> Create(PostMessageCreateDto newPostMessage)
+        public async Task<ServiceResult<int>> Create(PostMessageCreateDto newPostMessage)
         {
-            var result = new ServiceResult<PostMessage>();
+            var result = new ServiceResult<int>();
 
             var postMessage = _mapper.Map<PostMessage>(newPostMessage);
 
@@ -36,7 +36,7 @@ namespace Tsi1.BusinessLayer.Services
             _context.PostMessages.Add(postMessage);
             await _context.SaveChangesAsync();
 
-            result.Data = postMessage;
+            result.Data = postMessage.Id;
 
             return result;
         }
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/PostService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/PostService.cs
index 5c52e39..5472f25 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/PostService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/PostService.cs
@@ -25,9 +25,9 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<Post>> Create(PostCreateDto newPost)
+        public async Task<ServiceResult<int>> Create(PostCreateDto newPost)
         {
-            var result = new ServiceResult<Post>();
+            var result = new ServiceResult<int>();
 
             var post = _mapper.Map<Post>(newPost);
 
@@ -36,8 +36,7 @@ namespace Tsi1.BusinessLayer.Services
             _context.Posts.Add(post);
             await _context.SaveChangesAsync();
 
-            result.Data = post;
-
+            result.Data = post.Id;
             return result;
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/SectionItemService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/SectionItemService.cs
index 56cab25..b4294b0 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/SectionItemService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/SectionItemService.cs
@@ -39,6 +39,7 @@ namespace Tsi1.BusinessLayer.Services
             _context.SectionItems.Add(sectionItem);
             await _context.SaveChangesAsync();
 
+            result.Data = sectionItem.Id;
             return result;
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs
index 88f08b2..c27512f 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs
@@ -24,9 +24,9 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<bool>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId)
+        public async Task<ServiceResult<int>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId)
         {
-            var result = new ServiceResult<bool>();
+            var result = new ServiceResult<int>();
 
             var tenant = await _context.Tenants.FirstOrDefaultAsync(x => x.Id == tenantId);
 
@@ -47,10 +47,10 @@ namespace Tsi1.BusinessLayer.Services
             }
 
             survey.Tenant = tenant;
-            _context.Surveys.Add(survey);
-            
+            _context.Surveys.Add(survey);           
             await _context.SaveChangesAsync();
 
+            result.Data = survey.Id;
             return result;
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs
index 1e8f2b1..ca09556 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs
@@ -52,9 +52,9 @@ namespace Tsi1.BusinessLayer.Services
             return result;
         }
 
-        public async Task<ServiceResult<User>> Create(UserRegisterDto dto, string type, int tenantId)
+        public async Task<ServiceResult<int>> Create(UserRegisterDto dto, string type, int tenantId)
         {
-            var result = new ServiceResult<User>();
+            var result = new ServiceResult<int>();
 
             var user = _mapper.Map<User>(dto);
 
@@ -81,8 +81,8 @@ namespace Tsi1.BusinessLayer.Services
 
             _context.Users.Add(user);
             await _context.SaveChangesAsync();
-            result.Data = user;
 
+            result.Data = user.Id;
             return result;
         }
 
-- 
GitLab