Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Last active September 18, 2016 01:13
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 NickJosevski/05fb9c634569a8376002e4bf97171575 to your computer and use it in GitHub Desktop.
Save NickJosevski/05fb9c634569a8376002e4bf97171575 to your computer and use it in GitHub Desktop.
Used Guid - No lookup Azure Function
using System.Net;
public class UserInput
{
public string Guid {get;set;}
public string UsedBy { get;set;}
}
public class UsedGuidDocument
{
public string id { get; set; } // DocumentDB default id convention
public string UsedBy { get;set;}
}
public static bool UserInputIsValid(UserInput userData)
{
return !(userData == null || userData.Guid == null || userData.UsedBy == null);
}
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log,
out object doc, out string guidQueue)
{
// prep error case initially
var responseMsg = "Please pass a Guid and UsedBy in the request body";
var statusCode = HttpStatusCode.BadRequest;
var userData = req.Content.ReadAsAsync<UserInput>().Result;
if (UserInputIsValid(userData))
{
doc = new UsedGuidDocument { id = userData.Guid, UsedBy = userData.UsedBy };
statusCode = HttpStatusCode.OK;
responseMsg = $"Success {userData.Guid} - {userData.UsedBy}";
guidQueue = responseMsg;
}
else
{
doc = null; // because doc is `out` we need to set it to something
guidQueue = null; //same
}
return req.CreateResponse(statusCode, responseMsg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment