Created
June 8, 2013 13:37
-
-
Save wilfrem/5735197 to your computer and use it in GitHub Desktop.
ServiceStackのDTOのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ServiceStackDTOSample{ | |
[Api("アイテムをItemIDを元に取得")] | |
[Route("/items/{id}", "GET")] | |
public class GetItem : IReturn<Item> | |
{ | |
public string Id { get; set; } | |
} | |
[Api("アイテムを追加する")] | |
[Route("/items", "POST")] | |
public class AddItem : IReturn<Item> | |
{ | |
/// <summary> | |
/// アイテムのID(コード) | |
/// </summary> | |
public string Id { get; set; } | |
/// <summary> | |
/// アイテム名 | |
/// </summary> | |
public string Name { get; set; } | |
/// <summary> | |
/// アイテム種別 | |
/// </summary> | |
public string Type { get; set; } | |
/// <summary> | |
/// 委託したサークルのID | |
/// </summary> | |
public int CircleId { get; set; } | |
} | |
[Api("アイテムを編集する")] | |
[Route("/items/{Id}", "PUT")] | |
public class UpdateItem : AddItem { } | |
[Api("アイテムを削除する")] | |
[Route("/items/{Id}", "DELETE")] | |
public class DeleteItem : IReturn<Item> | |
{ | |
public string Id { get; set; } | |
} | |
/// <summary> | |
/// サークル情報の取得を行うサービス | |
/// </summary> | |
public class ItemService : Service | |
{ | |
public Item Get(GetItem request) | |
{ | |
return Db.Id<Item>(request.Id); | |
} | |
public Item Post(AddItem request) | |
{ | |
var entity = request.TranslateTo<Item>(); | |
Db.Insert<Item>(entity); | |
return entity; | |
} | |
public Item Put(UpdateItem request) | |
{ | |
Db.Update<Item>(request, q => q.Id == request.Id); | |
return Db.Id<Item>(request.Id); | |
} | |
public void Delete(DeleteItem request) | |
{ | |
Db.DeleteById<Item>(request.Id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment