public async Task Delete([FromBody] DeletePositionRequest request) { var position = await _positionRepository.GetByIdAsync(request.Id); if (position != null) { await _positionRepository.DeleteAsync(position); } }
/// <inheritdoc/> public void DeletePosition(DeletePositionRequest request) { if (request.Id == Guid.Empty) { throw new ArgumentException(); } if (!_employeePositionService.IsPositionOccupied(request.Id)) { _positionRepository.DeletePosition(request.Id); } else { throw new ArgumentOutOfRangeException(); } }
public ActionResult DeletePosition(DeletePositionRequest request) { try { _positionService.DeletePosition(request); return(Ok()); } catch (ArgumentOutOfRangeException) { return(StatusCode((int)HttpStatusCode.MethodNotAllowed, $"Position with id {request.Id} is occupied")); } catch (ArgumentException) { return(StatusCode((int)HttpStatusCode.NotAcceptable, "Id can not be empty")); } catch (Exception e) { _logger.LogError($"Error in DeletePosition: {e}"); return(StatusCode((int)HttpStatusCode.InternalServerError, e.ToString())); } }