public async Task <IActionResult> DisableSubjects(Guid studentId, Guid subjectId) { if (string.IsNullOrEmpty(studentId.ToString())) { return(NotFound()); } var student = await _repository.GetStudentAsync(studentId); if (student == null) { return(BadRequest("Student don`t exists")); } var subject = await _repository.GetSubjectAsync(subjectId); if (subject == null) { return(BadRequest("Subject won`t exists")); } // disable await _repository.DisableSubjectAsync(student.Id, subject.Id); await _repository.SaveAsync(); return(NoContent()); }
public async Task <ActionResult> PatchSubject(Guid subjectId, [FromBody] JsonPatchDocument <SubjectToUpdate> patchDocument) { if (patchDocument == null) { return(BadRequest()); } var subjectFromRepo = await _repository.GetSubjectAsync(subjectId); if (subjectFromRepo == null) { return(NotFound()); } var subjectToPatch = _mapper.Map <SubjectToUpdate>(subjectFromRepo); patchDocument.ApplyTo(subjectToPatch, ModelState); if (!TryValidateModel(subjectToPatch)) { return(ValidationProblem()); } _mapper.Map(subjectToPatch, subjectFromRepo); _repository.UpdateSubject(subjectFromRepo); await _repository.SaveAsync(); return(NoContent()); }