public async Task <IActionResult> PutAsync(int lessonId, int studentId, [FromBody] SaveLessonStudentResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var nu = _mapper.Map <SaveLessonStudentResource, LessonStudent>(resource); var result = await _lessonStudentService.UpdateAsync(lessonId, studentId, nu); if (!result.Success) { return(BadRequest(result.Message)); } var nuResource = _mapper.Map <LessonStudent, LessonStudentResource>(result.Resource); return(Ok(nuResource)); }
public async Task <IActionResult> PostAsync([FromBody] SaveLessonStudentResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var nu = _mapper.Map <SaveLessonStudentResource, LessonStudent>(resource); var result = await _lessonStudentService.SaveAsync(nu); if (!result.Success) { return(BadRequest(result.Message)); } await _lessonService.UpdateCountAsync(resource.LessonId); var nuResource = _mapper.Map <LessonStudent, LessonStudentResource>(result.Resource); Console.WriteLine(result.Resource.Lesson.Contador); return(Ok(nuResource)); }