Thursday, April 9, 2015

Jquery check textbox entered value is decimal with single dot for multiple textboxes

 <script type="text/javascript">

        $('input[id$=Text1],input[id$=Text2],input[id$=Text3]').keypress(function (event) {

            return isNumber(event, this)

        });


        // THE SCRIPT THAT CHECKS IF THE KEY PRESSED IS A NUMERIC OR DECIMAL VALUE.
        function isNumber(evt, element) {

            var charCode = (evt.which) ? evt.which : event.keyCode

            if (
                (charCode != 45 || $(element).val().indexOf('-') != -1) &&      // “-” CHECK MINUS, AND ONLY ONE.
                (charCode != 46 || $(element).val().indexOf('.') != -1) &&      // “.” CHECK DOT, AND ONLY ONE.
                (charCode < 48 || charCode > 57))
                return false;

            return true;
        }
    </script>

Wednesday, April 8, 2015

How to Create Web API in ASP.Net MVC

sql newid()

Yes, newid() is unique. newid() returns a globally unique identifier. newid() will be unique for each call of newid().
Thus, newid() can be used as the value of a primary key of a sql server table. Values returned by newid() can be inserted into a primary key column of type "uniqueidentifier". Here is an example of a "uniqueidentifier" primary key column, with newid() used as the default value:


CREATE TABLE [tblUsers] (
    [UserId] [uniqueidentifier] NOT NULL DEFAULT (newid()),
    [UserName] [varchar](256) NOT NULL,
    PRIMARY KEY ([UserId])
)

Select Dropdown option in jquery

CaseId=0; or
CaseId=1;or
CaseId=2; or
CaseId=3;
$('#ddl').val(CaseId);

sql get current date

Use GETDATE() function

Update Table_Name
set column= GETDATE()
where id = 1;

SQL UPDATE Syntax

UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

Why to choose Asp.Net Web API ?

  1. If we need a Web Service and don’t need SOAP, then ASP.Net Web API is best choice.
  2. It is Used to build simple, non-SOAP-based HTTP Services on top of existing WCF message pipeline.
  3. It doesn't have tedious and extensive configuration like WCF REST service.
  4. Simple service creation with Web API. With WCF REST Services, service creation is difficult.
  5. It is only based on HTTP and easy to define, expose and consume in a REST-ful way.
  6. It is light weight architecture and good for devices which have limited bandwidth like smart phones.
  7. It is open source.