Пример #1
0
        public async Task <IActionResult> GetActiveRateCategory([FromBody] int hotelId)
        {
            BaseResult <List <RateCategoryViewModel> > responseResult = new BaseResult <List <RateCategoryViewModel> >();

            if (hotelId <= default(int))
            {
                responseResult.IsError = true;
                responseResult.Message = string.Format(coreHelper.Constants.ErrorMessage.InvalidId, hotelId);
                return(BadRequest(responseResult));
            }
            BaseResult <List <RateCategory> > activeRateCategoryResult = new BaseResult <List <RateCategory> >();

            activeRateCategoryResult = await iRatesCategory.GetActiveRateCategory(hotelId);

            if (activeRateCategoryResult.IsError && activeRateCategoryResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }
            else if (activeRateCategoryResult.Result == null || !activeRateCategoryResult.Result.Any())
            {
                return(NoContent()); //204
            }
            responseResult.Result = RatesCategoryResponseMapper.MapToRateCategoryViewModel(activeRateCategoryResult.Result);
            return(Ok(responseResult));
        }
        public async Task <IActionResult> GetRateCategoryById([FromBody] int rateCategoryId)
        {
            BaseResult <RateCategoryViewModel> rateCategoryViewModelResult = new BaseResult <RateCategoryViewModel>();
            BaseResult <List <RateCategory> >  rateCategoryResult          = new BaseResult <List <RateCategory> >();
            BaseResult <List <RatePlans> >     ratePlansResult             = new BaseResult <List <RatePlans> >();
            RateCategory rateCategoryRequest = new RateCategory();

            if (rateCategoryId <= default(int))
            {
                rateCategoryResult.IsError = true;
                rateCategoryResult.Message = string.Format(coreHelper.Constants.ErrorMessage.InvalidId, rateCategoryId);
                return(BadRequest(rateCategoryResult));
            }

            rateCategoryResult = await iRatesCategory.GetRateCategoryById(rateCategoryId).ConfigureAwait(false);

            if (rateCategoryResult.IsError && rateCategoryResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }
            else if (rateCategoryResult.Result == null)
            {
                return(new NoContentResult()); //204
            }

            ratePlansResult = await iRatesCategory.GetRatePlansById(rateCategoryId).ConfigureAwait(false);

            if (ratePlansResult.IsError && ratePlansResult.ExceptionMessage != null)
            {
                return(new StatusCodeResult(500));
            }

            rateCategoryRequest = rateCategoryResult.Result.First();

            var result = RatesCategoryResponseMapper.MapToRateCategoryViewModel(rateCategoryRequest, ratePlansResult.Result);

            rateCategoryViewModelResult.Result = result;
            return(Ok(rateCategoryViewModelResult));
        }