Created
September 6, 2017 15:53
-
-
Save jeffhollan/798c1e69ced44c2fefe590cf8908594d 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
#r "Microsoft.WindowsAzure.Storage" | |
using Microsoft.WindowsAzure.Storage.Table; | |
using System.Net; | |
public static HttpResponseMessage Run(HttpRequestMessage req, IQueryable<Person> oncallTable, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
var startOfWeek = DateTimeExtension.StartOfWeek(DateTime.Now, DayOfWeek.Monday); | |
log.Info("Start of week: " + startOfWeek.ToString()); | |
Person person = oncallTable.Where(p => p.PartitionKey == "1" && p.RowKey == startOfWeek.ToString().Replace("/", "_")).AsEnumerable().FirstOrDefault(); | |
log.Info($"Oncall name: {person.Name} -- Oncall email: {person.Email}"); | |
return req.CreateResponse(HttpStatusCode.OK, person.Email); | |
} | |
public class Person : TableEntity | |
{ | |
public string Name { get; set; } | |
public string Email { get; set; } | |
} | |
public static class DateTimeExtension | |
{ | |
public static DateTime StartOfWeek(DateTime dt, DayOfWeek startOfWeek) | |
{ | |
int diff = dt.DayOfWeek - startOfWeek; | |
if (diff < 0) | |
{ | |
diff += 7; | |
} | |
return dt.AddDays(-1 * diff).Date; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment