Esempio n. 1
0
 /// <summary>
 /// Get a specific Continent.
 /// 1- Check input consistance.
 /// 2- Call service.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="service"></param>
 /// <returns></returns>
 public (int, string) Get(string id, ICoreCountriesService service)
 {
     //1-
     if (service == null)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
     //2-
     try
     {
         string continent = service.GetContinentByID(id);
         if (!String.IsNullOrEmpty(continent))
         {
             return(StatusCodes.Status200OK, continent);
         }
         else
         {
             return(StatusCodes.Status404NotFound, String.Empty);
         }
     }
     catch
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="service"></param>
        /// <param name="continentId"></param>
        /// <param name="languageID"></param>
        /// <returns></returns>
        public async Task <(int, IEnumerable <HRCountry>)> GetHRCountriesByContinentByLanguageAsync(
            ICoreCountriesService service,
            string continentId,
            string languageID)
        {
            Region region;

            if (service == null)
            {
                return(StatusCodes.Status500InternalServerError, null);
            }
            if (!Enum.TryParse(continentId, out region) || String.IsNullOrEmpty(languageID))
            {
                return(StatusCodes.Status400BadRequest, null);
            }
            else
            {
                try
                {
                    using (Task <IEnumerable <HRCountry> > task = service.GetHRCountriesByContinentByLanguageAsync(region, languageID))
                    {
                        await task;
                        return(StatusCodes.Status200OK, task.Result);
                    }
                }
                catch (Exception)
                {
                    return(StatusCodes.Status500InternalServerError, null);
                }
            }
        }
 /// <summary>
 /// Constructor for DI
 /// </summary>
 /// <param name="continentService">a continentservice (null not null)</param>
 /// <param name="logger">a logger (null allowed)</param>
 /// <param name="util">a IHRContinentControllerForker (null not allowed)</param>
 public HRContinentController(
     ICoreCountriesService continentService,
     ILogger <HRContinentController> logger,
     IHRContinentControllerForker util)
 {
     _continentService = continentService;
     _logger           = logger;
     _util             = util;
 }
 /// <summary>
 /// HRLangagesByContinentController constructor available for DI.
 /// </summary>
 /// <param name="countriesService">a Country service.</param>
 /// <param name="logger">a Logger.</param>
 /// <param name="util"> util forker.</param>
 public HRLangagesByContinentController(
     ICoreCountriesService countriesService,
     ILogger <HRLangagesByContinentController> logger,
     IHRLangagesByContinentControllerForker util)
 {
     _service = countriesService;
     _util    = util;
     _logger  = logger;
 }
Esempio n. 5
0
 /// <summary>
 /// TODO
 /// </summary>
 /// <param name="util"></param>
 /// <param name="service"></param>
 /// <param name="logger"></param>
 public HRCountriesByContinentByLangageController(
     IHRCountriesByContinentByLangageControllerForker util,
     ICoreCountriesService service,
     ILogger <HRCountriesByContinentByLangageController> logger
     )
 {
     _util    = util;
     _service = service;
     _logger  = logger;
 }
 /// <summary>
 /// Construcotr for DI.
 /// </summary>
 /// <param name="service">Country service.</param>
 /// <param name="config">MS Config.</param>
 /// <param name="forker">Country forker.</param>
 /// <param name="logger">MS logger.</param>
 public HRCountriesController(
     ICoreCountriesService service,
     IConfiguration config,
     IHRCountriesControllersForker forker,
     ILogger <HRCountriesController> logger)
 {
     _service = service;
     _config  = config;
     _forker  = forker;
     _logger  = logger;
 }
Esempio n. 7
0
 public HRCoreBordersService(IHRCoreRepository <HRBorder> repo,
                             IServiceWorkflowOnHRCoreRepository <HRBorder> workflow,
                             ILogger <HRCoreBordersService> logger,
                             ICoreCountriesService hrCountriesService)
 {
     _bordersRepository = repo;
     _workflow          = workflow;
     if (_workflow != null)
     {
         _workflow.MaxPageSize = _maxPageSize;
     }
     _logger             = logger;
     _hrCountriesService = hrCountriesService;
 }
Esempio n. 8
0
 /// <summary>
 /// Get All Continents.
 /// 1- Check input consistance.
 /// 2- Call service.
 /// </summary>
 /// <returns></returns>
 public (int, IEnumerable <string>) Get(ICoreCountriesService service)
 {
     //1-
     if (service == null)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
     //2-
     try
     {
         IEnumerable <string> continents = service.GetContinents();
         return(StatusCodes.Status200OK, continents);
     }
     catch
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 1- Process PagingInParameter if not supplied
        /// 2- Get the HRCountry from service
        /// 3- Paginate previous result
        /// </summary>
        /// <param name="pageModel">the paging model</param>
        /// <param name="orderBy">The order by clause</param>
        /// <param name="service">the Core countries service</param>
        /// <param name="maxPageSize">the maxPage size allowed for pagination.</param>
        /// <returns></returns>
        public async Task <(int, PagingParameterOutModel <HRCountry>)> GetFromPagingAsync(
            PagingParameterInModel pageModel,
            HRSortingParamModel orderBy,
            ICoreCountriesService service,
            ushort maxPageSize)
        {
            if (service != null && _util != null)
            {
                if (!_util.CanOrder(orderBy, service))
                {
                    return(StatusCodes.Status400BadRequest, null);
                }

                //!Add tu on this
                if (pageModel.PageSize > maxPageSize)
                {
                    return(StatusCodes.Status413PayloadTooLarge, null);
                }
                try
                {
                    //2-
                    Task <PagingParameterOutModel <HRCountry> > countriesAction = service.GetCountriesAsync(pageModel, orderBy);
                    await countriesAction;
                    //3-
                    return(StatusCodes.Status200OK, countriesAction.Result);
                }
                catch (IndexOutOfRangeException)
                {
                    //!Add tu on this
                    return(StatusCodes.Status416RequestedRangeNotSatisfiable, null);
                }
                catch (Exception)
                {
                    return(StatusCodes.Status500InternalServerError, null);
                }
            }
            else
            {
                return(StatusCodes.Status500InternalServerError, null);
            }
        }
 /// <summary>
 /// 1- Check input consitency.
 /// 2- call CoreCountriesService
 /// </summary>
 /// <param name="service"></param>
 /// <returns></returns>
 public async Task <(int, IEnumerable <Language>)> GetAllLangagesAsync(ICoreCountriesService service)
 {
     //1-
     if (service == null)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
     //2-
     try
     {
         using (Task <IEnumerable <Language> > task = service.GetAllLangagesAsync())
         {
             await task;
             return(StatusCodes.Status200OK, task.Result);
         }
     }
     catch (Exception)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Get a Country by ID (ALPHA2_3CODE)
 /// </summary>
 /// <param name="id">the country ID</param>
 /// <param name="service">the core countries service</param>
 /// <returns>the status code (http) and the Country.</returns>
 public async Task <(int, HRCountry)> GetFromIDAsync(string id, ICoreCountriesService service)
 {
     //1-
     if (String.IsNullOrEmpty(id))
     {
         //Could not happen as Get(PageModel = null) exists)
         return(StatusCodes.Status400BadRequest, null);
     }
     if (service == null)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
     //2-
     try
     {
         String           idToCompare   = id.ToUpper();
         Task <HRCountry> countryAction = service.GetCountryAsync(id);
         await            countryAction;
         //3-
         if (countryAction.Result != null)
         {
             //Last check necessary ??
             HRCountry candidateCountry = countryAction.Result;
             if ((!String.IsNullOrEmpty(candidateCountry.Alpha2Code) && candidateCountry.Alpha2Code.ToUpper() == idToCompare) ||
                 (!String.IsNullOrEmpty(candidateCountry.Alpha3Code) && (candidateCountry.Alpha3Code == idToCompare)))
             {
                 return(StatusCodes.Status200OK, countryAction.Result);
             }
             else
             {
                 return(StatusCodes.Status404NotFound, null);
             }
         }
         return(StatusCodes.Status404NotFound, null);
     }
     catch (Exception)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
        /// <summary>
        /// 1- Check input consitency.
        /// 2- Convert String to enum and call CoreCountriesService
        /// </summary>
        /// <param name="service">a Countryservice</param>
        /// <param name="continentId">a contientID (e.g : Africa)</param>
        /// <returns>Countries. Does not throw any exception. </returns>
        public async Task <(int, IEnumerable <HRCountry>)> GetHRCountriesByContinentAsync(ICoreCountriesService service, String continentId)
        {
            //1-
            Region region;

            if (service == null)
            {
                return(StatusCodes.Status500InternalServerError, null);
            }
            //2-
            if (!Enum.TryParse(continentId, out region))
            {
                return(StatusCodes.Status400BadRequest, null);
            }
            else
            {
                try
                {
                    using (Task <IEnumerable <HRCountry> > task = service.GetHRCountriesByContinentAsync(region))
                    {
                        await task;
                        return(StatusCodes.Status200OK, task.Result);
                    }
                }
                catch (Exception)
                {
                    return(StatusCodes.Status500InternalServerError, null);
                }
            }
        }
 public HRCountriesController(ICoreCountriesService service, IConfiguration config)
 {
     _service = service;
     _config  = config;
 }