Sunday, 10 June 2018

Access-Control-Allow-Origin Header in ASP.NET Core Web API


Add Setting in Startup Class.


 public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddCors();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseCors(builder =>
            {
                builder.AllowAnyHeader()
                       .AllowAnyOrigin()
                       .AllowAnyMethod();
            });
            app.UseMvc();
        }
    }

Wednesday, 7 March 2018

allow only numbers or decimal in textbox

Allow only numbers or decimal in textbox



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RNDWithNumbers.aspx.cs"
    Inherits="TabFormWebApp.RNDWithNumbers" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Script/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        function isNumberWithDecimalKey(evt, obj) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            var value = obj.value;
            var dotcontains = value.indexOf(".") != -1;
            if (dotcontains)
                if (charCode == 46) return false;
            if (charCode == 46) return true;
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }

        function isNumber(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        }

    </script>
</head>
<body>
    <form id="frm" runat="server">
    <table>
        <tr>
            <td>
                Only Number
            </td>
            <td>
                <input type="text" id="txtAllowNumber" onkeypress="return isNumber(event)" />
            </td>
        </tr>
        <tr>
            <td>
                Only Number With Decimal
            </td>
            <td>
                <input type="text" id="txtAllowNumberWithDecimal" onkeypress="return isNumberWithDecimalKey(event,this)" />
            </td>
        </tr>
    </table>
    <br />
    </form>
</body>
</html>

Friday, 2 February 2018

MongoDB CRUD Operations

MongoDB CRUD Operations

 CREATE DATABASE IN mongoDB

  MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it doesn't exist, otherwise it will return the existing database.

Syntax

syntax of create database is as follows - e.g. : use DataBaseName
Like :- use TestDB


Note :- CURD means  create, read, update, and delete

1 :- CREATE COLLECTION

MongoDB createCollection(name, options) is used to create collection.

e.g :- db.createCollection("Student", { size: 2147483648 } )



2 :- CREATE OPERATIONS
                       
syntax :- 1) db.collection.insertOne()
              2) db.collection.insertMany()  


Note:- (INSERT Data into Collection)

e.g :-1--) if insert one record

 db.Student.insertOne( { name: "mohan", class: "BCA", rollno :5} );

e.g :- 2--) if insert multiple record at one time

db.Student.insertMany( [
        { name: "mohan", class: "BCA", rollno :5},
        { name: "sohan", class: "MBA", rollno :15},
        { name: "ram", class: "BBA", rollno :10},
        { name: "shyam", class: "MCA", rollno :25},
   ] );


3 :- READ OPERATIONS

syntax : db.collection.find(query, projection)

e.g :- db.Student.find()

e.g :-1) db.Student.find({ name: "shyam" })

e.g :-2) db.Student.find( { rollno : 5 } )


4 :- UPDATE OPERATIONS


syntax :- db.collection.update(selectQuery, udateQuery)

e.g :-1 ) 

db.Student.update({'name':'shyam'},{$set:{'name':'shyam kumar'}})

db.Student.update({'id':'2'},{$set:{'name':'Mohan kumar'}})

e.g :-2) 

Note:- update class where rollno is greater than 10

db.Student.updateMany(
      { rollno : { $gt: 10 } },
      { $set: { "class" : 'PHD'} }
   );

5 :- DELETE OPERATIONS

syntax :-1 ) db.collection.deleteOne()
           :-2 ) db.collection.deleteMany()

e.g:- 1)

db.Student.deleteOne( { rollno : 4 } )




Factorial of a Number

Recently Viewed