Skip to content

Instantly share code, notes, and snippets.

@carcer
Created September 12, 2012 14:57
Show Gist options
  • Save carcer/3707194 to your computer and use it in GitHub Desktop.
Save carcer/3707194 to your computer and use it in GitHub Desktop.
[UriTemplate("/api/newsletter")]
public class PostNewsletter : IPost<Newsletter>, IOutput<NewsletterResponse>
{
private static dynamic Data { get { return Database.OpenConnection(GlobalSettings.DbDSN); } }
public NewsletterResponse Output { get; private set; }
public Status Post(Newsletter input)
{
var exists = Data.NewsletterSignup.FindByEmail(input.Email);
if ( exists == null)
{
Data.NewsletterSignup.Insert(input);
Output = NewsletterResponse.Inserted();
}else
{
Output = NewsletterResponse.AlreadyExists();
}
return 200;
}
}
[UriTemplate("/api/newsletter")]
public class GetNewsletterSignups : IGet, IOutput<IEnumerable<Newsletter>>
{
private static dynamic Data { get { return Database.OpenConnection(GlobalSettings.DbDSN); } }
public Status Get()
{
return 200;
}
public IEnumerable<Newsletter> Output
{
get
{
return Data.NewsletterSignup.All();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment