private IEnumerable <Domain.Models.Favorite> MapFavorites(IEnumerable <Data.Entities.Favorite> favorites) { var collection = new List <Domain.Models.Favorite>(); foreach (var favorite in favorites.ToList()) { var productMultilingual = _productRepository.GetProduct(favorite.Product.Id); var result = new Domain.Models.Favorite { Id = favorite.Id, UserId = Guid.Parse(favorite.UserId), Name = favorite.Name, Product = new Product { Id = favorite.ProductId, Name = productMultilingual.Name, VirtualName = productMultilingual.Name.RemoveDiacritics(), Modified = favorite.Product.Modified, Risk = new Risk { Description = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Description, Id = productMultilingual.Product.Risk.Id, Modified = productMultilingual.Product.Risk.Modified, Name = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Name }, Description = productMultilingual.Description } }; collection.Add(result); } return(collection.Count == 0 ? null : collection); }
public Domain.Models.Favorite GetFavorite(int favoriteId) { _logger.LogInformation($"BEGIN GetFavorite"); try { var favorite = _favoriteRepository.GetFavorite(favoriteId); if (favorite == null) { return(null); } var productMultilingual = _productRepository.GetProduct(favorite.Product.Id); var result = new Domain.Models.Favorite { Id = favorite.Id, UserId = Guid.Parse(favorite.UserId), Name = favorite.Name, Product = new Product { Id = favorite.ProductId, Name = productMultilingual.Name, VirtualName = productMultilingual.Name.RemoveDiacritics(), Modified = favorite.Product.Modified, Risk = new Risk { Description = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Description, Id = productMultilingual.Product.Risk.Id, Modified = productMultilingual.Product.Risk.Modified, Name = productMultilingual.Product.Risk.RisksMultilingual.FirstOrDefault(rm => rm.LanguageId == LanguageId).Name }, Description = productMultilingual.Description } }; return(result); } catch (Exception ex) { _logger.LogError($"Exception on GetBrand with message: {ex.Message}"); return(null); } }
public Domain.Models.Favorite GetFavorite(int favoriteId) { Domain.Models.Favorite result = null; try { _logger.LogInformation("BEGIN GetFavorite"); result = LactafarmaService.GetFavorite(favoriteId); _logger.LogInformation("END GetFavorite"); } catch (Exception ex) { _logger.LogError($"Exception on JsonResult called GetFavorite(favoriteId={favoriteId}) with message {ex.Message}"); } finally { if (result == null) { _logger.LogWarning("No results for current request!!!"); } } return(result); }