Last active
June 30, 2021 07:13
-
-
Save gistlyn/75f4b30fa009fcbcbfc2e48cef16b0b4 to your computer and use it in GitHub Desktop.
http-verbs
This file contains hidden or 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
[Route("/contacts", "GET")] | |
[Route("/contacts/{Id}", "GET")] | |
public class GetContacts : IReturn<List<Contact>> | |
{ | |
public int? Id { get; set; } | |
} | |
[Route("/contacts/{Id}", "PATCH PUT")] | |
public class UpdateContact : IReturn<Contact> | |
{ | |
public int Id { get; set; } | |
} | |
[Route("/contacts/{Id}", "DELETE")] | |
public class DeleteContact : IReturnVoid | |
{ | |
public int Id { get; set; } | |
} |
This file contains hidden or 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
public class ContactServices | |
{ | |
public object Get(GetContacts request) | |
{ | |
var contacts = request.Id == null ? | |
Db.Select<Contact>() : | |
Db.Select<Contact>(x => x.Id == request.Id.ToInt()); | |
return contacts; | |
} | |
public object Any(UpdateContact request) | |
{ | |
var contact = Db.SingleById<Contact>(request.Id); | |
contact.PopulateWith(request); | |
Db.Update(contact); | |
return contact; | |
} | |
public void Delete(DeleteContact request) => | |
Db.Delete<Contact>(x => x.Id == request.Id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment