Created
September 7, 2012 18:59
-
-
Save jpasichnyk/3668622 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
// route added in AppHost like: .Add<ReportFilter>("/Report/{StartDate}/{EndDate}"); | |
// call like: http://localhost:22015/api/Report/09-03-2012/09-07-2012 | |
public class ReportFilter | |
{ | |
public DateTime StartDate { get; set; } | |
public DateTime EndDate { get; set; } | |
} | |
public class ReportRow | |
{ | |
public DateTime SaleDate { get; set; } | |
public string TrackingCode { get; set; } | |
public int NumberOfSales { get; set; } | |
public double TotalSalesUSD { get; set; } | |
public double TotalCommissionsUSD { get; set; } | |
} | |
public class ReportResponse : IHasResponseStatus | |
{ | |
public IEnumerable<ReportRow> Report { get; set; } | |
public ResponseStatus ResponseStatus { get; set; } | |
} | |
public class ReportService : RestServiceBase<ReportFilter> | |
{ | |
public override object OnGet(ReportFilter request) | |
{ | |
//mock up some data just to test this out... | |
List<ReportRow> report = new List<ReportRow>(); | |
report.Add(new ReportRow() | |
{ | |
NumberOfSales = 12, | |
SaleDate = DateTime.Now.AddDays(-7), | |
TotalCommissionsUSD = 12.54, | |
TotalSalesUSD = 120.43, | |
TrackingCode = "Code1" | |
}); | |
report.Add(new ReportRow() | |
{ | |
NumberOfSales = 7, | |
SaleDate = DateTime.Now.AddDays(-7), | |
TotalCommissionsUSD = 1.54, | |
TotalSalesUSD = 12.43, | |
TrackingCode = "Code2" | |
}); | |
if (request.StartDate <= DateTime.Now.AddDays(-8)) | |
{ | |
report.Add(new ReportRow() | |
{ | |
NumberOfSales = 6, | |
SaleDate = DateTime.Now.AddDays(-8), | |
TotalCommissionsUSD = 2.54, | |
TotalSalesUSD = 22.43, | |
TrackingCode = "Code3" | |
}); | |
} | |
//always set the return TYPE to be constant based on the service/request type | |
return new ReportResponse() | |
{ | |
Report = report | |
}; | |
//return report; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment