cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
efnanozdemir
Regular Visitor

Azure function return values can not set to label

Hi everyone,

 

I'm beginner for canvas app and azure function, so I need some help. 

 

There is an azure function return "CurrentCustomer" object and CurrentCustomer has some string properties. I need to set this properties set to labels on canvas app. There is my code and canvas app. I clicked many times search button but no changes.

 

 

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Shop
{
    public static class GetCustomerInformation
    {
        [FunctionName("GetCustomerInformation")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "GetCustomerInformation")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string customer_phonenumber = req.Query["phonenumber"];


            Customer customer1 = new Customer();
            customer1.name = "Name1";
            customer1.surname = "Surname1";
            customer1.cardno = 1;
            customer1.phonenumber = "05343332211";

            Customer customer2 = new Customer();
            customer2.name = "Name2";
            customer2.surname = "Surname2";
            customer2.cardno = 2;
            customer2.phonenumber = "05343332212";

            Customer customer3 = new Customer();
            customer3.name = "Name3";
            customer3.surname = "Surname3";
            customer3.cardno = 3;
            customer3.phonenumber = "05343332213";


            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            customer_phonenumber = customer_phonenumber ?? data?.phonenumber;

            Customer CurrentCustomer = new Customer();

            if (customer_phonenumber != null)
            {
                switch(customer_phonenumber)
                {
                    case "05340816830":
                        CurrentCustomer = customer1;
                        break;
                    case "05340816831":
                        CurrentCustomer = customer2;
                        break;
                    default:
                        CurrentCustomer= customer3;
                        break;
                }
            }
            else
                CurrentCustomer = customer3;

            return new OkObjectResult(CurrentCustomer);
        }
    }
    public class Customer
    {
        public string name { get; set; }
        public string surname { get; set; }
        public int cardno { get; set; }
        public string phonenumber { get; set; }
    }

}

 

 

efnanozdemir_0-1660217561687.png

 

efnanozdemir_2-1660217638085.png

 

 

0 REPLIES 0

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (3,779)