Skip to content

Instantly share code, notes, and snippets.

@jeffhollan
Created September 6, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffhollan/798c1e69ced44c2fefe590cf8908594d to your computer and use it in GitHub Desktop.
Save jeffhollan/798c1e69ced44c2fefe590cf8908594d to your computer and use it in GitHub Desktop.
#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