Ejemplo n.º 1
0
        public async Task <ResponseModel <List <Favorite> > > GetAllClientFavoritesAsync(Guid clientId)
        {
            try
            {
                var favorites = await _favoriteRepository.GetAllClientFavorites(clientId);

                if (!favorites.Any())
                {
                    return(new ResponseModel <List <Favorite> >(true, new List <ErrorInfo>
                    {
                        new ErrorInfo(HttpStatusCode.NotFound, _messages.NoFavoritesFound,
                                      string.Format(_messages.NoFavoritesFoundDescription, clientId))
                    }));
                }

                foreach (var favorite in favorites)
                {
                    favorite.Product = await _productRepository.GetProduct(favorite.ProductId);
                }

                return(new ResponseModel <List <Favorite> >(favorites));
            }
            catch (Exception ex)
            {
                var message = string.Format(_messages.InternalErrorDescription, ex.Message);
                _logger.LogError(ex, message);

                return(new ResponseModel <List <Favorite> >(true, new List <ErrorInfo>
                {
                    new ErrorInfo(HttpStatusCode.InternalServerError, _messages.InternalError, message)
                }));
            }
        }