public async Task <IActionResult> DeleteLecturer(int id) { var lecturer = await _lecturerService.GetLecturerById(id); await _lecturerService.DeleteLecturer(lecturer); return(NoContent()); }
public async Task <ActionResult <Boolean> > DeleteLecturer(int id) { try { var LecturerForDelete = await _lecturerService.GetLecturer(id); if (LecturerForDelete == null) { return(NotFound($"Lecturer with this id = {id} is not found")); } return(await _lecturerService.DeleteLecturer(id)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorRetrievingDataFromDataBase)); } }
public async Task <IActionResult> Delete(int id) { if (id <= 0) { ModelState.AddModelError(nameof(id), "'id' must be positive."); return(BadRequest(ModelState)); } try { await _service.DeleteLecturer(id); return(Ok()); } catch (EntityNotFoundException) { return(BadRequest("Lecturer with such id does not exist.")); } catch (IncorrectIdException e) { _logger.LogWarning(e, "It seems, validation does not cover some errors."); return(BadRequest(e.Message)); } }