#Script Pages

<back to all web services

QueryCustomers

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.DataAnnotations;
using SharpScript;

namespace ServiceStack
{
    [DataContract]
    public partial class QueryBase
    {
        public QueryBase()
        {
            Meta = new Dictionary<string, string>{};
        }

        [DataMember(Order=1)]
        public virtual int? Skip { get; set; }

        [DataMember(Order=2)]
        public virtual int? Take { get; set; }

        [DataMember(Order=3)]
        public virtual string OrderBy { get; set; }

        [DataMember(Order=4)]
        public virtual string OrderByDesc { get; set; }

        [DataMember(Order=5)]
        public virtual string Include { get; set; }

        [DataMember(Order=6)]
        public virtual string Fields { get; set; }

        [DataMember(Order=7)]
        public virtual Dictionary<string, string> Meta { get; set; }
    }

    public partial class QueryDb<T>
        : QueryBase
    {
    }

    [DataContract]
    public partial class QueryResponse<Customer>
    {
        public QueryResponse()
        {
            Results = new List<Customer>{};
            Meta = new Dictionary<string, string>{};
        }

        [DataMember(Order=1)]
        public virtual int Offset { get; set; }

        [DataMember(Order=2)]
        public virtual int Total { get; set; }

        [DataMember(Order=3)]
        public virtual List<Customer> Results { get; set; }

        [DataMember(Order=4)]
        public virtual Dictionary<string, string> Meta { get; set; }

        [DataMember(Order=5)]
        public virtual ResponseStatus ResponseStatus { get; set; }
    }

}

namespace SharpScript
{
    public partial class Customer
    {
        public Customer()
        {
            Orders = new List<Order>{};
        }

        public virtual string CustomerId { get; set; }
        public virtual string CompanyName { get; set; }
        public virtual string Address { get; set; }
        public virtual string City { get; set; }
        public virtual string Region { get; set; }
        public virtual string PostalCode { get; set; }
        public virtual string Country { get; set; }
        public virtual string Phone { get; set; }
        public virtual string Fax { get; set; }
        public virtual List<Order> Orders { get; set; }
    }

    public partial class Order
    {
        public virtual int OrderId { get; set; }
        public virtual string CustomerId { get; set; }
        public virtual DateTime OrderDate { get; set; }
        public virtual double Total { get; set; }
    }

    public partial class QueryCustomers
        : QueryDb<Customer>
    {
        public virtual string CustomerId { get; set; }
        public virtual string CompanyNameContains { get; set; }
        public virtual string[] CountryIn { get; set; }
    }

}

C# QueryCustomers DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /json/reply/QueryCustomers HTTP/1.1 
Host: sharpscript.net 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"customerId":"String","companyNameContains":"String","countryIn":["String"],"skip":0,"take":0,"orderBy":"String","orderByDesc":"String","include":"String","fields":"String","meta":{"String":"String"}}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"offset":0,"total":0,"results":[{"customerId":"String","companyName":"String","address":"String","city":"String","region":"String","postalCode":"String","country":"String","phone":"String","fax":"String","orders":[{"orderId":0,"customerId":"String","orderDate":"\/Date(-62135596800000-0000)\/","total":0}]}],"meta":{"String":"String"},"responseStatus":{"errorCode":"String","message":"String","stackTrace":"String","errors":[{"errorCode":"String","fieldName":"String","message":"String","meta":{"String":"String"}}],"meta":{"String":"String"}}}