Beispiel #1
0
        public virtual async Task <ActionResult <PagedResultDtoEntity <TDtoEntity> > > GetAllByExample(PagedResultRequestDtoEntity <TDtoEntity> exampleSearchEntityPagingRequest)
        {
            try
            {
                IPagedResultRequestEntity <TEntity> pagedResultRequestEntity = _mapper.Map <IPagedResultRequestEntity <TEntity> >(exampleSearchEntityPagingRequest);

                IPagedResultEntity <TEntity> requestedCollection = _repository.GetAll(pagedResultRequestEntity);
                if (requestedCollection.TotalCount > 0)
                {
                    return(Ok(MapToPagedResultDtoEntity(_repository.GetAll(pagedResultRequestEntity))));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception apiControllerError)
            {
                _applicationLogTools.LogError(apiControllerError, new Dictionary <string, dynamic> {
                    { "ClassName", $"WebApi.ApiControllerBase<{typeof(TEntity).Name}>" }
                });
                if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(base.StatusCode(500, apiControllerError));
                }
                else
                {
                    return(base.StatusCode(500));
                }
            }
        }
        /// <summary>
        /// search results by parameter like
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public IPagedResultEntity <TEntity> GetAll(IPagedResultRequestEntity <TEntity> pagedResultRequestEntity = null)
        {
            PagedResultEntity <TEntity> pagedResultEntity = new PagedResultEntity <TEntity>();
            IQueryable <TEntity>        searchQuery;

            if (pagedResultRequestEntity != null && pagedResultRequestEntity.ObjectFilter != null)
            {
                searchQuery = SearchByPartiallyPopulatedEntity(pagedResultRequestEntity.ObjectFilter).AsQueryable();
            }
            else
            {
                searchQuery = _context.Set <TEntity>().AsQueryable();
            }

            pagedResultEntity.TotalCount     = searchQuery.Count();
            pagedResultEntity.ItemCollection = searchQuery.PagedSorted(pagedResultRequestEntity).ToList();

            return(pagedResultEntity);
        }
 /// <summary>
 /// Get all objects by partially populated object search in a sorted paged collection
 /// </summary>
 /// <param name="exampleSearchEntityPagingRequest"></param>
 /// <returns></returns>
 public virtual async Task <IPagedResultEntity <TEntity> > GetAllByExample(IPagedResultRequestEntity <TEntity> exampleSearchEntityPagingRequest)
 {
     try
     {
         return(await base.GetAllByExample(exampleSearchEntityPagingRequest));
     }
     catch (Exception apiRepositoryError)
     {
         _applicationLogTools.LogError(apiRepositoryError, new Dictionary <string, dynamic> {
             { "ClassName", $"AzureApi.ApiRepository<{typeof(TEntity).Name}>" }
         });
         if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development", StringComparison.InvariantCultureIgnoreCase))
         {
             throw;
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Get all objects by partially populated object search in a sorted paged collection
        /// </summary>
        /// <param name="exampleSearchEntityPagingRequest"></param>
        /// <param name="subPathUri"></param>
        /// <returns></returns>
        internal virtual async Task <IPagedResultEntity <TEntity> > GetAllByExample(IPagedResultRequestEntity <TEntity> exampleSearchEntityPagingRequest, string subPathUri = null)
        {
            IPagedResultEntity <TEntity> currentReturnCollection = null;

            if (string.IsNullOrWhiteSpace(subPathUri))
            {
                subPathUri = $"/api/{typeof(TEntity).Name}/GetAllByExample";
            }

            try
            {
                PagedResultRequestDtoEntity <TDtoEntity> pagedResultRequestEntity = base.MapToPagedResultRequestDtoEntity <TEntity, TDtoEntity>(exampleSearchEntityPagingRequest);

                HttpResponseMessage responseResult = await base.ApiPostAsync(pagedResultRequestEntity, subPathUri);

                responseResult.EnsureSuccessStatusCode();

                PagedResultDtoEntity <TDtoEntity> deserializedContent = JsonConvert.DeserializeObject <PagedResultDtoEntity <TDtoEntity> >(await responseResult.Content.ReadAsStringAsync());

                currentReturnCollection = base.MapToPagedResultEntity <TEntity, TDtoEntity>(deserializedContent);
            }
            catch (Exception apiCommunicationError)
            {
                _applicationLogTools.LogError(apiCommunicationError, new Dictionary <string, dynamic> {
                    { "ClassName", $"WebApi.ApiRepositoryStandard<{typeof(TEntity).Name}>" }
                });
                if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development", StringComparison.InvariantCultureIgnoreCase))
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }

            return(currentReturnCollection);
        }
Beispiel #5
0
        /// <summary>
        /// sorts and pages the result set or returns unsorted when pagedResultRequestEntity is null
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="searchQuery"></param>
        /// <param name="pagedResultRequestEntity"></param>
        /// <returns></returns>
        public static IEnumerable <TEntity> PagedSorted <TEntity>(this IEnumerable <TEntity> searchQuery, IPagedResultRequestEntity <TEntity> pagedResultRequestEntity)
        {
            if (pagedResultRequestEntity == null)
            {
                return(searchQuery);
            }

            if (string.IsNullOrWhiteSpace(pagedResultRequestEntity.SortRequest))
            {
                return(searchQuery);
            }
            else
            {
                return(searchQuery.AsQueryable().OrderBy(pagedResultRequestEntity.SortRequest)
                       .Skip(pagedResultRequestEntity.SkipCount)
                       .Take(pagedResultRequestEntity.MaxResultCount));
            }
        }
Beispiel #6
0
 internal PagedResultRequestDtoEntity <TDtoEntity> MapToPagedResultRequestDtoEntity <TEntity, TDtoEntity>(IPagedResultRequestEntity <TEntity> exampleSearchEntityPagingRequest)
 {
     try
     {
         return(_mapper.Map <PagedResultRequestDtoEntity <TDtoEntity> >(exampleSearchEntityPagingRequest));
     }
     catch (Exception apiRepositoryError)
     {
         _applicationLogTools.LogError(apiRepositoryError, new Dictionary <string, dynamic> {
             { "ClassName", $"WebApi.ApiControllerBase<{typeof(TEntity).Name}>" }
         });
         throw;
     }
 }