/// <summary> /// Finds a contact with the given primary key value as an asynchronous operation. /// </summary> /// <param name="id">The primary key for the item to be found.</param> /// <param name="fields">The fields to be included in the result set.</param> /// <param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken" /> used to propagate notifications that the operation should be canceled.</param> /// <returns> /// A <see cref="T:System.Threading.Tasks.Task`1" /> that represents the <see cref="T:Partnerinfo.Contact.ContactItem" /> of the asynchronous query. /// </returns> public virtual Task <ContactItem> FindByIdAsync(int id, ContactQueryFields fields, CancellationToken cancellationToken) { ThrowIfDisposed(); return(Contacts .Where(id) .Select(fields) .FirstOrDefaultAsync(cancellationToken)); }
public async Task <IActionResult> FindByIdAsync(int id, ContactQueryFields fields) { var contact = await _contactManager.FindByIdAsync(id, fields); if (contact == null) { return(NotFound()); } return(Ok(contact)); }
/// <summary> /// Projects each item of a sequence into a new form. /// </summary> internal static IQueryable <ContactItem> Select(this IQueryable <ContactItem> query, ContactQueryFields fields) { Expression <Func <ContactItem, ContactItem> > selector = c => new ContactItem { Id = c.Id }; if ((fields & ContactQueryFields.Sponsor) == ContactQueryFields.Sponsor) { selector = selector.Merge(c => new ContactItem { }); } if ((fields & ContactQueryFields.Attributes) == ContactQueryFields.Attributes) { selector = selector.Merge(c => new ContactItem { }); } if ((fields & ContactQueryFields.BusinessTags) == ContactQueryFields.BusinessTags) { selector = selector.Merge(c => new ContactItem { }); } return(query.Select(selector)); }
/// <summary> /// Finds a contact with the given primary key value as an asynchronous operation. /// </summary> /// <param name="id">The primary key for the item to be found.</param> /// <param name="fields">The fields to be included in the result set.</param> /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param> /// <returns> /// A task that represents the asynchronous operation. /// </returns> public virtual Task <ContactItem> FindByIdAsync(int id, ContactQueryFields fields) { ThrowIfDisposed(); return(Store.FindByIdAsync(id, fields, CancellationToken)); }