Monday, June 21, 2021

Find sum of two number without using any arithmetic operator.

class Program
    {
        static void Main(string[] args)
        {
 
            int a = 10, b = 5;
            if (b > 0)
            {
                while (b > 0)
                {
                    a++;
                    b--;
                }
            }
            // when 'b' is negative
            if (b < 0)
            { 
                while (b < 0)
                {
                    a--;
                    b++;
                }
            }
            Console.Write("Sum is: " + a);
        }
 
    }

Wednesday, March 17, 2021

How to implement request and response oAuth2 with RestSharp?



I am calling an API with access token that expire in 1799 seconds (approximately 30 minutes). What is the right to handle this? or how to use the refresh token to get a new access token, once the access token expires, without having to submit credentials again.

This is what I have so far:

public void api()
{
    string token = "";

    try {
        callApi(token);
    }
    catch(Exception)
    {
        var client = new RestClient("www.example.com/api/token");
        var request = new RestRequest(Method.POST);
        request.AddHeader("content-type", "application/x-www-form-urlencoded");
        request.AddHeader("cache-control", "no-cache");
        request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&username=us&password=pas", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);

        dynamic resp = JObject.Parse(response.Content);
        token = resp.access_token;

        callApi(token);
    }
}

public void callApi(string token)
{
    var client = new RestClient("www.example.com/api/data");
    var request = new RestRequest(Method.GET);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("authorization", "Bearer " + token);
    request.AddHeader("accept", "application/json; charset=utf-8");
    IRestResponse response = client.Execute(request);
}

} 

Sunday, September 15, 2019

List array removed and append the last in c#


class Program
    {
        static void Main(string[] args)
        {
            List<string> list1 = new List<string>();

            // list elements
            list1.Add("A");
            list1.Add("I");
            list1.Add("G");
            list1.Add("B");
            list1.Add("E");
            list1.Add("H");
            list1.Add("F");
            list1.Add("C");
            list1.Add("D");
            list1.Add("a");
            list1.Add("--Geen--");

            Console.WriteLine("Original List");
            List<string> list2 = new List<string>();
            for (int i = 0; i < list1.Count; i++)
            {
                if (list1[i].Contains("--Geen--"))
                {
                    list2.Add(list1[i]);
                    list1.RemoveAt(i);
                }
            }

            list1.Add(list2[0]);

            Console.WriteLine("\nSorted List");

            // use of List.Sort() method
            list1.Sort(StringComparer.Ordinal);


        }
    }

Thursday, December 20, 2018

open popup after form post

https://www.blogger.com/blogger.g?blogID=7765714418392902530#editor/src=sidebar

https://stackoverflow.com/questions/48311149/asp-net-mvc-post-not-working-on-popup-window

Tuesday, December 11, 2018

string format

https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting

https://stackoverflow.com/questions/16101100/string-format-input-string-was-not-in-correct-format-for-string-with-curly-brack

Friday, October 12, 2018

Nested Case Condition


CASE

                                         WHEN(P.PropertyId=115)    
                                         THEN
                                         ''
                                         ELSE
                                           CASE
                                              WHEN R.CompanyId is not null and R.CompanyId>0
                                                THEN CASE WHEN R.IsSeleComContForConfi = 1
                                                       THEN
                                                       AA.Pincode
                                                       ELSE
                                                       A.Pincode
                                                       END
                                                ELSE
                                                       A1.Pincode
                                            END   
                                    END AS  [Pincode]