Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active June 30, 2021 07:13
Show Gist options
  • Save gistlyn/75f4b30fa009fcbcbfc2e48cef16b0b4 to your computer and use it in GitHub Desktop.
Save gistlyn/75f4b30fa009fcbcbfc2e48cef16b0b4 to your computer and use it in GitHub Desktop.
http-verbs
[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; }
}
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