Пример #1
0
        public IActionResult GetBeers(string beerName)
        {
            bool isValidBeerName = Validations.ValidateBeerName(beerName);

            List <BeerArray> listOfBeers   = new List <BeerArray>();
            List <BeerDto>   listOfRatings = new List <BeerDto>();

            if (isValidBeerName)
            {
                listOfBeers = BeersDataStore.GetBeerByName(beerName);
                if (listOfBeers != null)
                {
                    listOfRatings = Utilities.JsonFiles.GetRatingsFromJson();
                }
                else
                {
                    //TODO Error
                }
            }
            else
            {
                return(BadRequest(string.Format("Invalid Beer Name/ Id {0}", beerName)));
            }
            return(Ok(Output.GenerateOutput(listOfBeers, listOfRatings)));
        }
        /// <summary>
        /// This method validates the beer name with the punk beer name
        /// </summary>
        /// <param name="beerName"></param>
        /// <returns>true or false</returns>
        public static bool ValidateBeerName(string beerName)
        {
            List <BeerArray> listOfBeers = new List <BeerArray>();

            listOfBeers = BeersDataStore.GetBeerByName(beerName);
            try
            {
                if (listOfBeers == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }