public IActionResult UpdateEnrollnment(Guid userId, Guid id, [FromBody] EnrollmentForUpdateDto enrollment) { if (enrollment == null) { _logger.LogError("enrollmentForUpdateDto object sent from client is null."); return(BadRequest("enrollmentForUpdateDto object is null")); } var user = _repository.User.GetUser(userId, trackChanges: false); if (user == null) { _logger.LogInfo($"User with id: {userId} doesn't exist in the database."); return(NotFound()); } var enrollmentEntity = _repository.Enrollment.GetOneEnrollmentForUser(userId, id, trackChanges: true); if (enrollmentEntity == null) { _logger.LogInfo($"Enrollment with id: {id} doesn't exist in the database."); return(NotFound()); } _mapper.Map(enrollment, enrollmentEntity); _repository.Save(); return(NoContent()); }
public IActionResult UpdateEnrollmentForSection(Guid sectionId, Guid id, [FromBody] EnrollmentForUpdateDto enrollment) { if (enrollment == null) { _logger.LogError("EnrollmentForUpdateDto object sent from client is null."); return(BadRequest("EnrollmentForUpdateDto object is null")); } var section = _repository.Section.GetSections(sectionId, trackChanges: false); if (section == null) { _logger.LogInfo($"Section with id: {sectionId} doesn't exist in the database."); return(NotFound()); } var enrollmentEntity = _repository.Enrollment.GetEnrollment(sectionId, id, trackChanges: true); if (enrollmentEntity == null) { _logger.LogInfo($"Section with id: {id} doesn't exist in the database."); return(NotFound()); } _mapper.Map(enrollment, enrollmentEntity); _repository.Save(); return(NoContent()); }
public async Task <IActionResult> UpdateEnrollmentForSection(Guid sectionId, Guid id, [FromBody] EnrollmentForUpdateDto enrollment) { var enrollmentEntity = HttpContext.Items["enrollment"] as Enrollment; _mapper.Map(enrollment, enrollmentEntity); await _repository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdateEnrollmentForUser(Guid userId, Guid id, [FromBody] EnrollmentForUpdateDto enrollment) { if (enrollment == null) { _logger.LogError("EnrollmentForUpdateDto object sent from client is null."); return(BadRequest("EnrollmentForUpdateDto object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the EnrollmentForUpdateDto object"); return(UnprocessableEntity(ModelState)); } var user = await _repository.User.GetUserAsync(userId, trackChanges : false); if (user == null) { _logger.LogInfo($"User with id: {userId} doesn't exist in the database."); return(NotFound()); } var enrollmentEntity = await _repository.SecEnrollmentMgt.GetEnrollmentAsync(userId, id, trackChanges : true); if (enrollmentEntity == null) { _logger.LogInfo($"Enrollment with id: {id} doesn't exist in the database."); return(NotFound()); } _mapper.Map(enrollment, enrollmentEntity); await _repository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdateEnrollmentForSection(Guid sectionId, Guid id, [FromBody] EnrollmentForUpdateDto enrollment) { /* if (enrollment == null) * { * _logger.LogError("EnrollmentForUpdateDto object sent from client is null."); * return BadRequest("EnrollmentForUpdateDto object is null"); * } * * if (!ModelState.IsValid) * { * _logger.LogError("Invalid model state for the EmployeeForUpdateDto object"); * return UnprocessableEntity(ModelState); * } * * * var section =await _repository.Section.GetSectionsAsync(sectionId, trackChanges: false); * if (section == null) * { * _logger.LogInfo($"Section with id: {sectionId} doesn't exist in the database."); * return NotFound(); * } * * var enrollmentEntity =await _repository.Enrollment.GetEnrollmentAsync(sectionId, id, trackChanges: true); * if (enrollmentEntity == null) * { * _logger.LogInfo($"Section with id: {id} doesn't exist in the database."); * return NotFound(); * } */ var enrollmentEntity = HttpContext.Items["enrollment"] as Enrollment; _mapper.Map(enrollment, enrollmentEntity); await _repository.SaveAsync(); return(NoContent()); }