Ejemplo n.º 1
0
        /// <summary>
        /// Return the hotel brands
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> GetHotelBrands(int id)
        {
            BaseResult <List <HotelBrandViewModel> > hotelBrandResult = new BaseResult <List <HotelBrandViewModel> >();

            if (id < 1)
            {
                hotelBrandResult.Message = Constants.BadRequestErrorMessage.InvalidChainRequest;
                return(BadRequest(hotelBrandResult));
            }
            var cacheData = RedisCacheHelper.Instance.Get <List <HotelBrandViewModel> >(Constants.CacheKeys.HotelBrandList);

            if (cacheData != null && cacheData.Any())
            {
                hotelBrandResult.Result = cacheData;
            }
            else
            {
                BaseResult <List <HotelBrand> > HotelBrandResultData = await iMasterData.GetHotelBrands().ConfigureAwait(false);

                if (HotelBrandResultData.IsError && HotelBrandResultData.ExceptionMessage != null)
                {
                    return(new StatusCodeResult(500));
                }
                else if (HotelBrandResultData.Result == null || HotelBrandResultData.Result.Count == 0)
                {
                    return(NoContent()); //204
                }
                else
                {   // mapping model to viewmodel
                    List <HotelBrandViewModel> hotelBrandListAll = DbMapperMasterdata.MapAllHotelBrands(HotelBrandResultData);
                    hotelBrandResult.Result = hotelBrandListAll;
                    RedisCacheHelper.Instance.Set <List <HotelBrandViewModel> >(Constants.CacheKeys.HotelBrandList, hotelBrandListAll, false);
                }
            }
            hotelBrandResult.Result = hotelBrandResult.Result.Where(p => p.HotelChainId == id).ToList();
            return(Ok(hotelBrandResult)); //200
        }