コード例 #1
0
        public async Task <Dictionary <ServiceDictionaryKey, object> > TryGetFavoriteFood(int patientId)
        {
            Dictionary <ServiceDictionaryKey, object> dictionary = new Dictionary <ServiceDictionaryKey, object>();


            try
            {
                List <Food> foods = await _foodRepository.Favorites(patientId);

                if (foods.Count <= 0)
                {
                    dictionary.Add(ServiceDictionaryKey.ERROR, $"No favorites found for given ID: {patientId}.");
                    dictionary.Add(ServiceDictionaryKey.HTTPSTATUSCODE, HttpStatusCode.NotFound);
                    return(dictionary);
                }

                dynamic data = _messageSerializer.Serialize(foods);
                dictionary.Add(ServiceDictionaryKey.VALUE, data);
            }
            catch (Exception ex)
            {
                dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler);
            }

            return(dictionary);
        }