Ejemplo n.º 1
0
        public async Task <ActionResult <IList <BatchDto> > > Get(string state)
        {
            if (string.IsNullOrWhiteSpace(state))
            {
                return(BadRequest("state (ex. Fresh, ExpiresToday, Expired) must be passed as parameter"));
            }

            if (!Enum.TryParse <FreshnesState>(state, true, out FreshnesState freshnesState))
            {
                return(BadRequest($"state is not supported state (ex. Fresh, ExpiresToday, Expired"));
            }

            try
            {
                _logger.LogDebug($"{nameof(Get)} Started");
                IList <BatchDto> result = null;

                var repoObj = await _summaryRepository.GetFreshness(freshnesState);

                if (repoObj == null)
                {
                    return(NotFound());
                }

                result = _mapper.Map <IList <BatchDto> >(repoObj);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, nameof(Get), null);
            }
            return(null);
        }