Skip to content

Instantly share code, notes, and snippets.

@NickJosevski

NickJosevski/UsedGuidBasicInput.cs Secret

Last active Sep 18, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.