From cfdc46f407f11efbd066df43a01b429a44eb659a Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Wed, 28 Oct 2020 18:45:25 -0300
Subject: [PATCH] fixes

---
 Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs     |  4 ++--
 Tsi1.Api/Tsi1.Api/Controllers/PostController.cs      | 10 +++++++++-
 Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs |  2 +-
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs b/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
index a34cad3..ce849fa 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs
@@ -36,7 +36,7 @@ namespace Tsi1.Api.Controllers
             return Ok(result.Data);
         }
 
-        [Authorize(UserTypes.Professor)]
+        [Authorize(Roles = UserTypes.Professor)]
         [HttpPost("Create")]
         public async Task<IActionResult> Create(ForumCreateDto newForum)
         {
@@ -50,7 +50,7 @@ namespace Tsi1.Api.Controllers
             return Ok();
         }
 
-        [Authorize(UserTypes.Professor)]
+        [Authorize(Roles = UserTypes.Professor)]
         [HttpDelete("Delete/{forumId}")]
         public async Task<IActionResult> Delete(int forumId)
         {
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
index 7c64c6c..99c0674 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/PostController.cs
@@ -61,8 +61,16 @@ namespace Tsi1.Api.Controllers
 
             var userEmails = await _forumService.GetSubscribedUsers(newPost.ForumId);
 
-            await _emailService.NotifyNewPostOrMessage(newPost, userEmails.Data);
+            if (userEmails.Data.Any())
+            {
+                var resultEmail = await _emailService.NotifyNewPostOrMessage(newPost, userEmails.Data);
 
+                if (resultEmail.HasError)
+                {
+                    return BadRequest(resultEmail.Message);
+                }
+            }
+            
             return Ok();
         }
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
index 4d204ca..1865a42 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/ForumService.cs
@@ -30,7 +30,7 @@ namespace Tsi1.BusinessLayer.Services
         {
             var result = new ServiceResult<Forum>();
 
-            var existingForum = _context.Forums
+            var existingForum = await _context.Forums
                 .FirstOrDefaultAsync(x => x.Name == newForum.Name && x.CourseId == newForum.CourseId);
 
             if (existingForum != null)
-- 
GitLab