public virtual async Task <Contact> GetContactByIdAsync(string contactId) { if (contactId == null) { throw new ArgumentNullException(nameof(contactId)); } Contact result = null; var cacheKey = CacheKey.With(GetType(), "GetContactByIdAsync", contactId); var dto = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var contactDto = await _customerApi.GetContactByIdAsync(contactId); if (contactDto != null) { cacheEntry.AddExpirationToken(CustomerCacheRegion.CreateChangeToken(contactDto.Id)); cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken()); } return(contactDto); }); if (dto != null) { result = dto.ToContact(); if (!dto.Organizations.IsNullOrEmpty()) { //Load contact organization result.Organization = await GetOrganizationByIdAsync(dto.Organizations.FirstOrDefault()); } } return(result); }
public async Task <IDictionary <string, object> > GetMemberIndexByIdAsync(string memberId) { ValidateParameters(memberId); var cacheKey = CacheKey.With(GetType(), "GetMemberIndexByIdAsync", memberId); var result = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var indexDto = await _demoSearchApi.GetDocumentIndexAsyncAsync(nameof(Member), memberId); cacheEntry.AddExpirationToken(CustomerCacheRegion.CreateChangeToken(memberId)); cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken()); return(indexDto); }); return(result); }
public async Task <Organization> GetOrganizationByIdAsync(string organizationId) { Organization result = null; var cacheKey = CacheKey.With(GetType(), "GetOrganizationByIdAsync", organizationId); var dto = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var organizationDto = await _customerApi.GetOrganizationByIdAsync(organizationId); if (organizationDto != null) { cacheEntry.AddExpirationToken(CustomerCacheRegion.CreateChangeToken(organizationDto.Id)); cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken()); } return(organizationDto); }); if (dto != null) { result = dto.ToOrganization(); //Lazy load organization contacts result.Contacts = new MutablePagedList <Contact>((pageNumber, pageSize, sortInfos, @params) => { var criteria = new OrganizationContactsSearchCriteria { OrganizationId = result.Id, PageNumber = pageNumber, PageSize = pageSize }; if (!sortInfos.IsNullOrEmpty()) { criteria.Sort = SortInfo.ToString(sortInfos); } if (@params != null) { criteria.CopyFrom(@params); } return(SearchOrganizationContacts(criteria)); }, 1, 20); } return(result); }
public virtual async Task <Contact> GetContactByIdAsync(string contactId) { Contact result = null; var cacheKey = CacheKey.With(GetType(), "GetContactByIdAsync", contactId); var dto = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var contactDto = await _customerApi.GetContactByIdAsync(contactId); if (contactDto != null) { cacheEntry.AddExpirationToken(CustomerCacheRegion.CreateChangeToken(contactDto.Id)); } return(contactDto); }); if (dto != null) { result = dto.ToContact(); result.Orders = LazyLoadCustomerOrders(result); result.QuoteRequests = LazyLoadCustomerQuotes(result); result.Subscriptions = LazyLoadCustomerSubscriptions(result); } return(result); }