Created
September 12, 2012 14:57
-
-
Save carcer/3707194 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
[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