From c1b636dcc759af3a6467d62bbceb6bdd55a5d916 Mon Sep 17 00:00:00 2001
From: Lucca Santangelo <luccasant95@gmail.com>
Date: Wed, 9 Dec 2020 20:24:50 -0300
Subject: [PATCH] asd

---
 .../Tsi1.Api/Controllers/CourseController.cs  | 40 +++++++++++--------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
index 47e7344..5414320 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
 using System.Security.Claims;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Authorization;
@@ -62,24 +63,31 @@ namespace Tsi1.Api.Controllers
         [HttpPost("Matriculate/{courseId}")]
         public async Task<IActionResult> Matriculate(int courseId)
         {
-            var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
-            var user = await _userService.GetById(userId);
-
-            var response = await _bedeliaService.IsValidUser(user.Data.Student.IdentityCard);
-            if (response.HasError)
-            {
-                return BadRequest(response.Message);
-            }
-
-            var result = await _courseService.Matriculate(userId, courseId);
-            if (result.HasError)
+            try
             {
-                return BadRequest(result.Message);
+                var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
+                var user = await _userService.GetById(userId);
+
+                var response = await _bedeliaService.IsValidUser(user.Data.Student.IdentityCard);
+                if (response.HasError)
+                {
+                    return BadRequest(response.Message);
+                }
+
+                var result = await _courseService.Matriculate(userId, courseId);
+                if (result.HasError)
+                {
+                    return BadRequest(result.Message);
+                }
+
+                if (result.Data == false)
+                {
+                    return NotFound(result.Message);
+                }
             }
-
-            if (result.Data == false)
+            catch (Exception ex)
             {
-                return NotFound(result.Message);
+                return BadRequest(ex.Message);
             }
 
             return Ok();
-- 
GitLab