diff --git a/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs b/Tsi1.Api/Tsi1.Api/Controllers/ForumController.cs index a34cad3f2a12a8128da4362cc316a077d7b189b1..ce849fad5a8181e60e393cc4ddfc226540111847 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 7c64c6c2d027f352c60633d935e7911475b4b593..99c067406816c9bb85dda0af24997f2408b6fd81 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 4d204ca1ff885a61661eb6b996acb95195bf71d1..1865a424afa5cce020312e80eb3b5492318ed13f 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)