Saturday, October 1, 2022

Call Web API Post method from Jquery

 $(document).ready(function () {

            $(".btn_click").click(function () {


                var FullName = $("#FullName").val();

                var Mobile_Number = $("#Mobile_Number").val();

                var Email = $("#Email").val();

                var Investment_Amount = $("#Investment_Amount").val();

                var Country = $('[id$=Country] option:selected').val();

                var STO_ID = $("input[name='sto']:checked").map(function () {

                    return this.value;

                }).get().join(',');


                ;

                var UserRegister = new Object();


                UserRegister.FullName = FullName;

                UserRegister.Mobile_Number = Mobile_Number;

                UserRegister.Email = Email;

                UserRegister.Investment_Amount = Investment_Amount;

                UserRegister.Country = Country;

                UserRegister.STO_ID = STO_ID;


                $.ajax({

                    url: 'https://localhost:44334/api/Register',

                    type: 'POST',

                    dataType: 'json',

                    contentType: 'application/json; charset=utf-8',

                    data: JSON.stringify(UserRegister),

                    success: function (data, textStatus, xhr) {

                        console.log(data);

                    },

                    error: function (xhr, textStatus, errorThrown) {

                        console.log('Error in Operation');

                    }

                });


            });

        });



C#




Make a class with all that fields



Add this CORS line in the following order in Startup file


    public void ConfigureServices(IServiceCollection services)

        {

          

            string URL= Convert.ToString(Configuration["URLConfig:RegisterZcrypto"]);


            services.AddCors(options =>

            {

                options.AddPolicy("CorsPolicy",

                    builder => builder.WithOrigins(URL)

                    .AllowAnyMethod()

                    .AllowAnyHeader());

                //.AllowCredentials());

            });

            services.AddControllers();

        }


       public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

            if (env.IsDevelopment())

            {

                app.UseDeveloperExceptionPage();

            }


            app.UseHttpsRedirection();


            app.UseRouting();

            app.UseCors("CorsPolicy");

            app.UseAuthorization();


            app.UseEndpoints(endpoints =>

            {

                endpoints.MapControllers();

                endpoints.MapGet("/", async context =>

                {

                    await context.Response.WriteAsync("Welcome to running ASP.NET Core on AWS Lambda");

                });

            });


          

        }






Thursday, August 4, 2022

Convert JSON object in to class

 https://stackoverflow.com/questions/11126242/using-jsonconvert-deserializeobject-to-deserialize-json-to-a-c-sharp-poco-class

Get the rate from Binance

 Get the rate from Binance


HTTP POST Request:

https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search


Parameters:

{  "asset": "USDT",

    "fiat": "CNY",

    "merchantCheck": true,

    "page": 1,

    "payTypes": ["BANK"],

    "publisherType": null,

    "rows": 20,

    "tradeType": "BUY",

    "transAmount":  "5000"

}


Parameters:


asset: Currently available asset USDT, BTC, BNB, BUSD, ETH, DAI.


fiat: Its long, visit sanchezmarcos.


merchantCheck: Well i don't know its use, but value is null, true, false.


page: The endpoint is paginated.


payTypes: An array of payment types example BANK, GoMoney, CashDeposit etc.


payTypes depend on fiat used so you might not see some of these but there's a lot of payment types.


publisherType: I'm only aware of merchant.


row: Amount of rows from 1 - 20.


tradeType: BUY or SELL.


transAmount: Filter merchant by amount.


Note The api is for binance internal operation which means it can change any time


Ref:

https://stackoverflow.com/questions/67793326/api-binance-p2p-i-only-access-a-part-only-the-buy-and-not-all-of-it-buy-and-s

Monday, August 1, 2022

Get the text between two string with C#

 


public static string getBetween(string strSource, string strStart, string strEnd)

{

    if (strSource.Contains(strStart) && strSource.Contains(strEnd))

    {

        int Start, End;

        Start = strSource.IndexOf(strStart, 0) + strStart.Length;

        End = strSource.IndexOf(strEnd, Start);

        return strSource.Substring(Start, End - Start);

    }


    return "";

}


string source = "This is an example string and my data is here";

string data = getBetween(source, "my", "is");


Reference:

https://stackoverflow.com/questions/10709821/find-text-in-string-with-c-sharp

Wednesday, June 29, 2022

ocelot

 I need to implement ocelot for our project these are the some useful links might help from security to load balancer




(API Gateway/Ocelot with Microservices)

https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core/ [different gateway for different interfaces]


https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core-part-two/ (JWT in Ocelot)

https://www.c-sharpcorner.com/article/how-to-use-jwt-authentication-with-web-api/

https://www.c-sharpcorner.com/article/asp-net-web-api-2-creating-and-validating-jwt-json-web-token/


https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core-part-three-logging2/ (Logging with Ocelot)


https://www.blinkingcaret.com/2018/05/30/refresh-tokens-in-asp-net-core-web-api/ (Refreshing Bearer Token Automatically On Expiry)



Load-Balancing in OCELOT

https://ocelot.readthedocs.io/en/latest/features/loadbalancer.html

LeastConnection | CookieStickySessions |  | CustomLoadBalancer


ASP.NET Core Example for Load-Balancing with OCELOT

----------------------------------------------------

http://www.developerin.net/a/85-Ocelot-API-Gateway/144-Load-Balancing-with-Ocelot-API-Gateway



Ocelot OverAll Functionality

-------------------------------

https://altkomsoftware.pl/en/blog/building-api-gateways-with-ocelot/

Saturday, June 25, 2022

Run all SQL files in a directory

 if you want to executethe SQL multiples files 

first step 

Place the files in that order number is the best option so it will come in that order you want to execute


1.sql

2.sql

3.sql






Now the main step place this .BAT file in the directory from which you want the .SQL files to be executed, double click the .BAT file and you are done!


we have two options to create a .bat file

1-with if you want to give user and password for that sql server connection 

2-second one is with out password.


------------------------------------This one is for without Password-----------------------------------------


for %%G in (*.sql) do sqlcmd /S servername /d databaseName -E -i"%%G"

pause

 

------------------------------------This one is for with User and Password-----------------------------------------


for %%G in (*.sql) do sqlcmd /S servername /d databaseName -U username -P 

password -i"%%G"


Note that the "-E" is not needed when user/password is provided