public static async Task <IActionResult> GetEvents( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage incomingRequest, [Blob("vedastro-site-data/EventDataList.xml", FileAccess.ReadWrite)] BlobClient eventDataListClient) { var responseMessage = ""; try { //get person list from storage var eventDataListXml = APITools.BlobClientToXml(eventDataListClient); //get data needed to generate events var requestData = APITools.ExtractDataFromRequest(incomingRequest); //parse it var person = Person.FromXml(requestData.Element("Person")); var startTime = Time.FromXml(requestData.Element("StartTime").Element("Time")); var endTime = Time.FromXml(requestData.Element("EndTime").Element("Time")); var location = GeoLocation.FromXml(requestData.Element("Location")); var tag = Tools.XmlToAnyType <EventTag>(requestData.Element(typeof(EventTag).FullName)); var precision = Tools.XmlToAnyType <double>(requestData.Element(typeof(double).FullName)); //calculate events from the data received var events = CalculateEvents(startTime, endTime, location, person, tag, precision, eventDataListXml); //convert events to XML for sending var rootXml = new XElement("Root"); foreach (var _event in events) { rootXml.Add(_event.ToXml()); } responseMessage = rootXml.ToString(); } catch (Exception e) { //format error nicely to show user responseMessage = APITools.FormatErrorReply(e); } var okObjectResult = new OkObjectResult(responseMessage); return(okObjectResult); }
public static async Task <IActionResult> UpdatePerson( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage incomingRequest, [Blob(PersonlistXml, FileAccess.ReadWrite)] BlobClient personListClient) { var responseMessage = ""; try { //get unedited hash & updated person details from incoming request var requestData = APITools.ExtractDataFromRequest(incomingRequest); var originalHash = int.Parse(requestData?.Element("PersonHash").Value); var updatedPersonXml = requestData?.Element("Person"); //get the person record that needs to be updated var personListXml = APITools.BlobClientToXml(personListClient); var personToUpdate = personListXml.Root.Elements() .Where(delegate(XElement personXml) { //use hash as id to find the person's record var thisHash = Person.FromXml(personXml).GetHashCode(); return(thisHash == originalHash); }).First(); //delete the previous person record, //and insert updated record in the same place personToUpdate.ReplaceWith(updatedPersonXml); //upload modified list to storage await APITools.OverwriteBlobData(personListClient, personListXml); responseMessage = new XElement("Status", "Success").ToString(); } catch (Exception e) { //format error nicely to show user responseMessage = APITools.FormatErrorReply(e); } var okObjectResult = new OkObjectResult(responseMessage); return(okObjectResult); }
public static async Task <IActionResult> GetPerson( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage incomingRequest, [Blob(PersonlistXml, FileAccess.ReadWrite)] BlobClient personListClient) { var responseMessage = ""; try { //get person name var requestData = APITools.ExtractDataFromRequest(incomingRequest); //parse it var personName = requestData.Value; //get person list from storage var personListXml = APITools.BlobClientToXml(personListClient); //get only female ppl into a list var foundPerson = from person in personListXml.Root?.Elements() //todo need to use hash here for checking where person.Element("Name")?.Value == personName select person; //send person to caller responseMessage = new XElement("Root", foundPerson.FirstOrDefault()).ToString(); } catch (Exception e) { //format error nicely to show user responseMessage = APITools.FormatErrorReply(e); } var okObjectResult = new OkObjectResult(responseMessage); return(okObjectResult); }