コード例 #1
0
ファイル: Quotes.cs プロジェクト: iansrobinson/Restbucks
        public HttpResponseMessage<Shop> Post(Shop shop, HttpRequestMessage<Shop> request)
        {
            if (shop == null)
            {
                var errorResponse = new HttpResponseMessage {StatusCode = HttpStatusCode.BadRequest};

                errorResponse.Headers.CacheControl = new CacheControlHeaderValue {NoCache = true, NoStore = true};
                errorResponse.Content = new StringContent("Bad request: empty or malformed data.");
                errorResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                throw new HttpResponseException(errorResponse);
            }

            var quote = quotationEngine.CreateQuote(new QuotationRequest(shop.Items.Select(i => new QuotationRequestItem(i.Description, new Quantity(i.Amount.Measure, i.Amount.Value)))));
            var baseUri = uriFactory.CreateBaseUri<Quotes>(request.RequestUri);

            var body = new ShopBuilder(baseUri)
                .AddItems(quote.LineItems.Select(li => new LineItemToItem(li).Adapt()))
                .AddLink(new Link(uriFactory.CreateRelativeUri<Quote>(quote.Id), RestbucksMediaType.Value, LinkRelations.Self))
                .AddLink(new Link(uriFactory.CreateRelativeUri<OrderForm>(quote.Id), RestbucksMediaType.Value, LinkRelations.OrderForm))
                .Build();

            var response = new HttpResponseMessage<Shop>(body, HttpStatusCode.Created);

            response.Headers.Location = uriFactory.CreateAbsoluteUri<Quote>(baseUri, quote.Id);
            response.Headers.CacheControl = new CacheControlHeaderValue {NoCache = true, NoStore = true};

            return response;
        }
コード例 #2
0
ファイル: Form.cs プロジェクト: iansrobinson/Restbucks
        public Form(string id, Uri resource, string method, string mediaType, Uri schema, Shop instance)
        {
            CheckString.Is(Not.NullOrEmptyOrWhitespace, id, "id");
            Check.IsNotNull(resource, "resource");
            CheckString.Is(Not.NullOrEmptyOrWhitespace, method, "method");
            CheckString.Is(Not.NullOrEmptyOrWhitespace, mediaType, "mediaType");

            this.id = id;
            this.resource = resource;
            this.method = method;
            this.mediaType = mediaType;
            this.schema = schema;
            this.instance = instance;
        }
コード例 #3
0
 private static Form GetForm(string id, Shop entityBody)
 {
     return (from f in entityBody.Forms
             where f.Id.Equals(id)
             select f).FirstOrDefault();
 }
コード例 #4
0
ファイル: Form.cs プロジェクト: iansrobinson/Restbucks
 public Form(string id, Uri resource, string method, string mediaType, Shop instance)
     : this(id, resource, method, mediaType, null, instance)
 {
 }