コード例 #1
0
ファイル: PoliciesController.cs プロジェクト: antcorpinc/Dew
        /// <summary>
        /// Gets policy cancellation charges from MasterData
        /// </summary>
        /// <returns>returns cancellation charges :- First night / full charge</returns>
        public async Task <IActionResult> GetCancellationCharges()
        {
            var cancellationChargesCache = new BaseResult <List <CancellationChargesViewModel> >()
            {
                Result = RedisCacheHelper.Instance.Get <List <CancellationChargesViewModel> >(Constants.CacheKeys.CancellationChargesList)
            };

            if (cancellationChargesCache.Result == null || cancellationChargesCache.Result.Count == 0)
            {
                var cancellationChargesResult = await iPolicies.GetCancellationCharges().ConfigureAwait(false);

                if (cancellationChargesResult.IsError && cancellationChargesResult.ExceptionMessage != null)
                {
                    return(StatusCode(500, cancellationChargesResult));
                }
                else if (cancellationChargesResult.Result == null || cancellationChargesResult.Result.Count == 0)
                {
                    return(NoContent()); //204
                }
                else
                {
                    var chargesListVm = DbMapperMasterdata.MapCancellationCharges(cancellationChargesResult);
                    RedisCacheHelper.Instance.Set <List <CancellationChargesViewModel> >(Constants.CacheKeys.CancellationChargesList, chargesListVm.Result);
                    return(Ok(chargesListVm)); //200
                }
            }
            return(Ok(cancellationChargesCache));
        }