public virtual async Task UpdateContactAsync(Contact contact) { await _customerApi.UpdateContactAsync(contact.ToContactDto()); //Invalidate cache CustomerCacheRegion.ExpireMember(contact.Id); }
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 virtual async Task DeleteContactAsync(string contactId) { await _customerApi.DeleteContactsAsync(new[] { contactId }); //Invalidate cache CustomerCacheRegion.ExpireMember(contactId); }
public async Task UpdateOrganizationAsync(Organization organization) { var orgDto = organization.ToOrganizationDto(); await _customerApi.UpdateOrganizationAsync(orgDto); CustomerCacheRegion.ExpireMember(organization.Id); }
public virtual async Task UpdateContactAddressesAsync(string contactId, IList <Address> addresses) { var existContact = await GetContactByIdAsync(contactId); if (existContact != null) { await _customerApi.UpdateAddessesAsync(contactId, addresses.Select(x => x.ToCustomerAddressDto()).ToList()); //Invalidate cache CustomerCacheRegion.ExpireMember(existContact.Id); } }
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 virtual async Task UpdateContactAsync(string contactId, ContactUpdateInfo contactUpdateInfo) { var existContact = await GetContactByIdAsync(contactId); if (existContact != null) { existContact.FirstName = contactUpdateInfo.FirstName; existContact.LastName = contactUpdateInfo.LastName; existContact.Email = contactUpdateInfo.Email; var contactDto = existContact.ToCustomerContactDto(); await _customerApi.UpdateContactAsync(contactDto); //Invalidate cache CustomerCacheRegion.ExpireCustomer(existContact.Id); } }
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 override async Task DeleteContactAsync(string contactId) { try { await _customerApi.DeleteContactsAsync(new[] { contactId }); } catch (HttpOperationException ex) { /* Our AutoRestClient throws exception on NoContent status code. * In order not to touch the customer module, we check that the exception status is 'NoContent' * and in this case we continue execution */ if (!ex.Message.Contains(NO_CONTENT, StringComparison.InvariantCulture)) { throw; } } //Invalidate cache CustomerCacheRegion.ExpireMember(contactId); }
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); }