Created
June 22, 2011 13:58
-
-
Save stirno/1040135 to your computer and use it in GitHub Desktop.
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 DTNX.DNS.RestServices | |
{ | |
public class RestServiceBase<T, TRepository> : ServiceStack.ServiceInterface.RestServiceBase<T> where T : ModelBase where TRepository : IRepository<T> | |
{ | |
public TRepository Repository { get; set; } | |
public override object OnGet(T request) | |
{ | |
var baseRequest = request.TranslateTo<ModelBase>(); | |
if (baseRequest.Id == default(int)) | |
{ | |
return Repository.GetAll(); | |
} | |
return Repository.Get(baseRequest.Id); | |
} | |
public override object OnPut(T request) | |
{ | |
return base.OnPut(request); | |
} | |
public override object OnPost(T request) | |
{ | |
return Repository.Save(request); | |
} | |
public override object OnDelete(T request) | |
{ | |
return Repository.Delete(request); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment