Ejemplo n.º 1
0
        public Task <long> Count <T>(ISpecification <T> specification)
            where T : class, ISearchable
        {
            var domainName = typeof(T).FullName;

            if (specification == null)
            {
                return(Http.Get <long>(
                           URL + "count/" + domainName,
                           new[] { HttpStatusCode.OK }));
            }

            var gs = specification as GenericSpecification <T>;

            if (gs != null)
            {
                return
                    (Http.Call <GenericSpecification <T>, long>(
                         URL + "count-generic/" + domainName,
                         "PUT",
                         gs,
                         new[] { HttpStatusCode.OK }));
            }
#if !PORTABLE
            var es = specification as ExpressionSpecification <T>;
            if (es != null)
            {
                return
                    (Http.Call <LambdaExpressionNode, long>(
                         URL + "count-expression/" + domainName,
                         "PUT",
                         es.Expression,
                         new[] { HttpStatusCode.OK }));
            }
#endif

            var specName = ProxyHelper.GetSpecificationDomainName(specification);
            return(Http.Call <ISpecification <T>, long>(
                       URL + "count/" + domainName + "/" + specName,
                       "POST",
                       specification,
                       new[] { HttpStatusCode.OK }));
        }
Ejemplo n.º 2
0
        public Task <T[]> Search <T>(ISpecification <T> specification, int?limit, int?offset, IDictionary <string, bool> order)
            where T : class, ISearchable
        {
            var domainName = typeof(T).FullName;

            var limitOffsetOrder = string.Empty;

            if (limit != null)
            {
                limitOffsetOrder += "limit=" + limit;
            }
            if (offset != null)
            {
                limitOffsetOrder += (limitOffsetOrder.Length > 0 ? "&" : string.Empty) + "offset=" + offset;
            }
            if (order != null && order.Count > 0)
            {
                limitOffsetOrder +=
                    (limitOffsetOrder.Length > 0 ? "&" : string.Empty)
                    + "order="
                    + string.Join(
                        ",",
                        order.Select(it => (it.Value ? string.Empty : "-") + it.Key).ToArray());
            }
            if (limitOffsetOrder.Length > 0)
            {
                limitOffsetOrder = "?" + limitOffsetOrder;
            }

            if (specification == null)
            {
                return(Http.Get <T[]>(
                           URL + "search/" + domainName + limitOffsetOrder,
                           new[] { HttpStatusCode.OK }));
            }

            var specName = ProxyHelper.GetSpecificationDomainName(specification);

            var gs = specification as GenericSpecification <T>;

            if (gs != null)
            {
                return
                    (Http.Call <GenericSpecification <T>, T[]>(
                         URL + "search-generic/" + domainName + limitOffsetOrder,
                         "PUT",
                         gs,
                         new[] { HttpStatusCode.OK }));
            }
#if !PORTABLE
            var es = specification as ExpressionSpecification <T>;
            if (es != null)
            {
                return
                    (Http.Call <LambdaExpressionNode, T[]>(
                         URL + "search-expression/" + domainName + limitOffsetOrder,
                         "PUT",
                         es.Expression,
                         new[] { HttpStatusCode.OK }));
            }
#endif

            return(Http.Call <ISpecification <T>, T[]>(
                       URL + "search/" + domainName + "/" + specName + limitOffsetOrder,
                       "POST",
                       specification,
                       new[] { HttpStatusCode.OK }));
        }