Beispiel #1
0
        public async Task GetOrganizations_WithoutArchived_ResultContainsDeletedOrganizations()
        {
            // Arrange
            const int testCustomerId = 3000;

            var deletedOrganization = new Organization
            {
                Id         = Guid.NewGuid(),
                CustomerId = testCustomerId,
                IsDeleted  = true
            };
            var activeOrganization = new Organization
            {
                Id         = Guid.NewGuid(),
                CustomerId = testCustomerId,
                IsDeleted  = false
            };
            var searchDto = new OrganizationSearchDto
            {
                IncludeArchived = true
            };

            this.organizationsRepository.Refresh(new List <Organization> {
                deletedOrganization, activeOrganization
            });

            // Act
            var actual = await this.sut.GetOrganizations(testCustomerId, searchDto);

            // Assert
            Assert.IsTrue(actual.Results.Contains(deletedOrganization));
            Assert.IsTrue(actual.Results.Contains(activeOrganization));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> GetOrganizations(
            int customerId,
            [FromUri] OrganizationSearchDto request
            )
        {
            var response = await organizationsControllerHelper.GetOrganizations(customerId, request);

            return(Ok(response));
        }
Beispiel #3
0
        /// <summary>
        /// Gets customers.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <PagedResultDto <OrganizationResponseDto> > GetOrganizations(int customerId, OrganizationSearchDto request)
        {
            var result = await organizationsService.GetOrganizations(customerId, request);

            return(Mapper.Map <PagedResult <Organization>, PagedResultDto <OrganizationResponseDto> >(result));
        }
        /// <summary>
        /// Gets the organizations.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <PagedResult <Organization> > GetOrganizations(int customerId, OrganizationSearchDto request)
        {
            Expression <Func <Organization, bool> > expression = o => o.CustomerId == customerId;

            if (request != null)
            {
                if (!string.IsNullOrEmpty(request.Q))
                {
                    var terms = request.Q.Split(' ').Where(r => !string.IsNullOrWhiteSpace(r));

                    foreach (var term in terms)
                    {
                        expression = expression.And(o => o.Name.Contains(term));
                    }
                }

                if (!request.IncludeArchived)
                {
                    expression = expression.And(o => !o.IsDeleted);
                }
            }

            return(await organizationRepository
                   .FindPagedAsync(
                       expression,
                       o => o.OrderBy(e => e.Id),
                       null,
                       request != null?request.Skip : (int?)null,
                       request != null?request.Take : (int?)null
                       ));
        }