using System.Collections.Generic; using System.Linq; using Sony.Filtr.Buzz; using Sony.Filtr.Contracts.Entities.Buzz; using Sony.Filtr.Utility.Extensions; namespace Sony.Filtr.AdminAPI.ViewModels { public class BuzzOwnerViewModelHelper { private readonly BuzzAccountManager _buzzAccountManager; public BuzzOwnerViewModelHelper(BuzzAccountManager buzzAccountManager) { _buzzAccountManager = buzzAccountManager; } public BuzzOwnerViewModel BuildBuzzOwner(BuzzUser buzzUser) { if (buzzUser == null) return null; var categories = _buzzAccountManager.GetBuzzCategories(); var buzzCateogoriesLookup = categories.ToDictionary(k => k.ID, v => v.Name); return BuildBuzzOwner(buzzUser, buzzCateogoriesLookup); } public BuzzOwnerViewModel BuildBuzzOwner(BuzzUser buzzUser, Dictionary buzzCategoriesLookup) { if (buzzUser == null) return null; return new BuzzOwnerViewModel() { AccountId = buzzUser.Username, AccountName = buzzUser.DisplayName ?? buzzUser.Username, CategoryId = buzzUser.BuzzCategoryId, CategoryName = buzzUser.BuzzCategoryId.HasValue ? buzzCategoriesLookup.GetValueOrDefault(buzzUser.BuzzCategoryId.Value) : null, MarketCode = buzzUser.CountryCode }; } } }