From 7497781df622e0bb843a87621b0709fa84697929 Mon Sep 17 00:00:00 2001 From: Lucca Santangelo <luccasant95@gmail.com> Date: Sun, 29 Nov 2020 16:28:57 -0300 Subject: [PATCH] close record fix --- Bedelia/Controllers/CoursesController.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Bedelia/Controllers/CoursesController.cs b/Bedelia/Controllers/CoursesController.cs index 429ad89..56e4e8d 100644 --- a/Bedelia/Controllers/CoursesController.cs +++ b/Bedelia/Controllers/CoursesController.cs @@ -111,10 +111,13 @@ namespace Bedelia.Controllers public async Task<IActionResult> CloseRecord(CloseRecordDto closeRecord) { var now = DateTime.Now; - var courseId = await _context.Courses - .Where(x => x.Name == closeRecord.CourseName) - .Select(x => x.Id) - .FirstOrDefaultAsync(); + var course = await _context.Courses + .FirstOrDefaultAsync(x => x.Name == closeRecord.CourseName); + + if (course == null) + { + return BadRequest(string.Format(@"No existe el curso con nombre {0} en bedelia", closeRecord.CourseName)); + } var userIdentityCards = closeRecord.UserGrades.Select(x => x.IdentityCard); @@ -132,7 +135,7 @@ namespace Bedelia.Controllers userCourses.Add(new UserCourse() { - CourseId = courseId, + CourseId = course.Id, UserId = user.Id, Grade = grade, GradeDate = now -- GitLab