Пример #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));
                }
            }
        }
Пример #2
0
 internal virtual PagedResultDtoEntity <TDtoEntity> MapToPagedResultDtoEntity(IPagedResultEntity <TEntity> pagedResultEntity)
 {
     try
     {
         return(_mapper.Map <PagedResultDtoEntity <TDtoEntity> >(pagedResultEntity));
     }
     catch (Exception apiControllerError)
     {
         _applicationLogTools.LogError(apiControllerError, new Dictionary <string, dynamic> {
             { "ClassName", $"WebApi.ApiControllerBase<{typeof(TEntity).Name}>" }
         });
         throw;
     }
 }
Пример #3
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);
        }