Skip to content

Instantly share code, notes, and snippets.

@tswann
tswann / Relationships.cs
Created September 21, 2011 13:15
Linking an Account and Contact entity via a relationship.
Account account = new Account();
_contact.FirstName = "Jim";
_context.AddRelatedObject(account, new Relationship("relationship_name"), contact);
_context.AddObject(account);
_context.UpdateObject(contact);
_context.SaveChanges();
@tswann
tswann / gist:3762876
Created September 21, 2012 17:43
Get (all)
> curl http://localhost:51307/api/tasks
[
{"Id":1,"Subject":"Test","Description":"Some interestingish text"},
{"Id":2,"Subject":"Test 2","Description":"Some more text"}
]
@tswann
tswann / gist:3762879
Created September 21, 2012 17:44
Sample API Controller
using System.Collections.Generic;
using System.Web.Http;
using System.Net.Http;
using TaskManager.Models;
using System.Linq;
using System.Net;
using System;
namespace TaskManager.Controllers
{
@tswann
tswann / gist:3763012
Created September 21, 2012 18:08
Sample Web API routes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace TaskManager
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
@tswann
tswann / gist:3763065
Created September 21, 2012 18:21
GET
> curl http://localhost:51307/api/tasks -v
> GET /api/tasks HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
@tswann
tswann / gist:3763084
Created September 21, 2012 18:26
GET (id)
> curl http://localhost:51307/api/tasks/1 -i
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RDpcU09VUkNFXHBsdXJhbHNpZ2h0XG12YzRcVGFza01hbmFnZXJcVGFza01hbmFnZXJcYXBpXHRhc2tzXDE=?=
@tswann
tswann / gist:3763163
Created September 21, 2012 18:43
GET (xml)
> curl http://localhost:51307/api/tasks -H "Accept: application/xml"
<ArrayOfTask xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/TaskMana
ger.Models"><Task><Description>Some interestingish text</Description><Id>1</Id><Subject>Test</Subject></Task><Task><Desc
ription>Some more text</Description><Id>2</Id><Subject>Test 2</Subject></Task></ArrayOfTask>
@tswann
tswann / gist:3763228
Created September 21, 2012 18:57
DELETE
> curl http://localhost:51307/api/tasks/2 -X DELETE -v
> DELETE /api/tasks/2 HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
@tswann
tswann / gist:3763266
Created September 21, 2012 19:05
POST
> curl http://localhost:51307/api/tasks -X POST -d "id=2&subject=test&description=blah" -v
> POST /api/tasks HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-pc-win32) libcurl/7.23.1 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:51307
> Accept: */*
> Content-Length: 34
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 34 out of 34 bytes
@tswann
tswann / Create Entity.cs
Created November 1, 2012 16:15
Example of creating a custom Dynamics CRM entity using the Xrm SDK.
CreateEntityRequest createrequest = new CreateEntityRequest
{
//Define the entity
Entity = new EntityMetadata
{
SchemaName = _customEntityName,
DisplayName = new Label("Bank Account", 1033),
DisplayCollectionName = new Label("Bank Accounts", 1033),
Description = new Label("An entity to store information about customer bank accounts", 1033),