/// <summary> /// Retrieve a specific Border. /// 1- Check consistancy /// 1.2- Create Task on GetBorder's repository action /// 1.3- Return Result action with no more processing /// 2- Throw Exception if consistancy is KO. /// </summary> /// <param name="borderID">a BorderID to retrieve.</param> /// <returns>The border with ID. /// Throw MemberAccessException if repository is null.</returns> public async Task <HRBorder> GetBorderAsync(String borderID) { HRBorder retour = null; //1- if (_bordersRepository != null) { //1.2- using (Task <HRBorder> bordersTask = _bordersRepository.GetAsync(borderID)) { await bordersTask; //1.3- retour = bordersTask.Result; } } //2- else { if (_logger != null) { _logger.LogError("_bordersRepository is null in HRCoreBordersServices"); } throw new MemberAccessException(); } return(retour); }
public CoreBordersServiceStub(List <String> bordersID) { if (bordersID != null) { foreach (String iterator in bordersID) { HRBorder borderi = new HRBorder() { FIPS = iterator }; _list.Add(borderi); } } }
/// <summary> /// 1- Check input consistance. /// 2- Call service async. /// 3- Process result of action as a single HRBorder. /// </summary> /// <param name="id">the FIPS value searched.</param> /// <param name="borderService">the Border service.</param> /// <returns>StatusCode, HRBorder result.</returns> public async Task <(int, HRBorder)> GetFromIDAsync(String id, ICoreBordersService borderService) { //1- if (_util == null) { return(StatusCodes.Status500InternalServerError, null); } if (String.IsNullOrEmpty(id)) { //Could not happen as Get(PageModel = null) exists) return(StatusCodes.Status400BadRequest, null); } if (borderService == null) { return(StatusCodes.Status500InternalServerError, null); } //2- try { Task <HRBorder> bordersAction = borderService.GetBorderAsync(id); await bordersAction; //3- HRBorder resultAction = bordersAction.Result; if (resultAction != null) { if (!String.IsNullOrEmpty(resultAction.FIPS) && resultAction.FIPS.ToUpper() == id.ToUpper()) { return(StatusCodes.Status200OK, resultAction); } else { return(StatusCodes.Status404NotFound, null); } } return(StatusCodes.Status404NotFound, null); } catch (Exception) { return(StatusCodes.Status500InternalServerError, null); } }