Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Operator '==' cannot be applied to operands of type 'Task' and 'bool' (CS0019)

$
0
0

Hi,

How to avoid:

Error CS0019: Operator '==' cannot be applied to operands of type 'Task' and 'bool' (CS0019)

In below code?

public partial class AboutMerchant : ContentView
{
    public AboutMerchant()
    {
        InitializeComponent();

        if (!Application.Current.Properties.ContainsKey("ZeeraCustomerID"))
        {
            App.Current.MainPage = new NavigationPage(new ZeeraSignin());
        }
        else
        {
            // indicatorLoading.IsRunning = true;

            if (!Application.Current.Properties.ContainsKey("ZeeraMerchantNumber"))
            {
                App.Current.MainPage.DisplayAlert("Error", "You must select a merchant first.", "OK");
                Application.Current.MainPage.Navigation.PopAsync();
                return;
            }

            GetMerchantDetails Merchant = new GetMerchantDetails();

            if (Merchant.MerchantDetails(Convert.ToString(Application.Current.Properties["ZeeraMerchantNumber"])) == true)
            {
                // await DisplayAlert("Scanned Barcode", "EXISTS", "OK");

                // await Navigation.PushAsync(new ZeeraCategory());

                // this.Title = Convert.ToString(Application.Current.Properties["ZeeraMerchantName"]);

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = Convert.ToString(Application.Current.Properties["ZeeraMerchantProfile"]);

                lblProfile.Source = htmlSource;

                loadingProfile.IsVisible = false;
                lblProfile.IsVisible = true;

                // GetCategory();
            }
            else
            {
                App.Current.MainPage.DisplayAlert("Error", "Unable to find merchant details.!\nCode: " + Convert.ToString(Application.Current.Properties["ZeeraMerchantNumber"]), "OK");
            }
        }
    }
}

My GetMerchantDetails is a Class:

using System;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Text;

namespace Zeera
{
    public class GetMerchantDetails
    {
        public async Task<bool> MerchantDetails(string merchant_number)
        {
            var client = new HttpClient();
            client.BaseAddress = new Uri("https://www.domain.com/ws/get_merchant_details.php?merchant=" + merchant_number);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = await client.GetAsync("https://www.domain.com/ws/get_merchant_details.php?merchant=" + merchant_number);

            if (response.IsSuccessStatusCode)
            {
                var data = await response.Content.ReadAsStringAsync();

                dynamic merchantdata = JsonConvert.DeserializeObject(data);

                if (merchantdata.ToString() == "False")
                {
                    return false;
                }
                else
                {
                    App.Current.Properties.Remove("ZeeraMerchantNumber");
                    App.Current.Properties.Remove("ZeeraMerchantGuid");
                    App.Current.Properties.Remove("ZeeraMerchantName");
                    App.Current.Properties.Remove("ZeeraMerchantProfile");
                    App.Current.Properties.Remove("ZeeraMerchantCountry");
                    App.Current.Properties.Remove("ZeeraMerchantEmail");
                    App.Current.Properties.Remove("ZeeraMerchantCurrency");
                    App.Current.Properties.Remove("ZeeraMerchantActive");
                    App.Current.Properties.Remove("ZeeraMerchantBlocked");

                    App.Current.Properties.Add("ZeeraMerchantNumber", merchantdata[0].merchant_number);
                    App.Current.Properties.Add("ZeeraMerchantGuid", merchantdata[0].merchant_guid);
                    App.Current.Properties.Add("ZeeraMerchantName", merchantdata[0].merchant_name);
                    App.Current.Properties.Add("ZeeraMerchantProfile", merchantdata[0].merchant_profile);
                    App.Current.Properties.Add("ZeeraMerchantCountry", merchantdata[0].country_code);
                    App.Current.Properties.Add("ZeeraMerchantEmail", merchantdata[0].email_address);
                    App.Current.Properties.Add("ZeeraMerchantCurrency", merchantdata[0].base_currency);
                    App.Current.Properties.Add("ZeeraMerchantActive", merchantdata[0].is_active);
                    App.Current.Properties.Add("ZeeraMerchantBlocked", merchantdata[0].is_blocked);
                    await App.Current.SavePropertiesAsync();

                    return true;
                }
            }

            return false;
        }
    }
}

Kindly help..

Thanks,
Jassim


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>