/// <summary> /// The list. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="input"> /// The input. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// The argument null exception. /// </exception> /// <exception cref="Exception"> /// The exception. /// </exception> public async Task <HumanListResponse> List(Guid owner, HumanListRequest input) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (input == null) { throw new ArgumentNullException(nameof(input)); } //TODO: Add validations var ownerExits = await this.humanRepository.ExistOwner(owner); if (!ownerExits) { throw new Exception("User doesnt exist."); } return(await this.humanRepository.List(owner, input)); }
/// <summary> /// The list. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="input"> /// The input. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <HumanListResponse> List(Guid owner, HumanListRequest input) { IQueryable <PersonEntity> listQuery = this.context.Persons.Where(i => i.Code != owner && i.OwnerCode == owner && ((!input.Filter.BringArchived && !i.IsArchived) || input.Filter.BringArchived)); if (!string.IsNullOrEmpty(input.Filter.AnyName)) { listQuery = input.Filter.AnyNameExact ? listQuery.Where(x => x.Name == input.Filter.AnyName || x.Surname == input.Filter.AnyName) : listQuery.Where(x => x.Name.Contains(input.Filter.AnyName) || x.Surname.Contains(input.Filter.AnyName)); } if (!string.IsNullOrEmpty(input.Filter.Email)) { listQuery = input.Filter.EmailExact ? listQuery.Where(x => x.Name == input.Filter.Email) : listQuery.Where(x => x.Email.Contains(input.Filter.Email)); } var queryResult = await listQuery.CountAsync(); var orderType = input.Order.IsDesc ? SortOrder.Descending : SortOrder.Ascending; var list = await listQuery .OrderByFieldPerson(orderType, input.Order.Field) .Skip((input.Page - 1) * input.ItemsPerPage) .Take(input.ItemsPerPage) .Select(personEntity => GetHumanOut(personEntity)).ToListAsync(); var result = new HumanListResponse { NumberOfItems = queryResult, Data = list }; return(result); }
/// <summary> /// The list. /// </summary> /// <param name="code"> /// The code. /// </param> /// <param name="input"> /// The input. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <HttpResponseMessage> List(Guid code, HumanListRequest input) { throw new NotImplementedException(); }
public async Task <HttpResponseMessage> List(Guid owner, HumanListRequest input) { this.Validator.Page(input).Items(input); return(await this.ProcessActionAsync(owner, input, this.humanService.List)); }