Monday, November 28, 2011
Tuesday, September 27, 2011
Convert IEnumerable of String to Int
Code
// ids is an IEnumerable of String
var integers = ids.Select(x => int.Parse(x));
// to convert and sort at the same time:
var sortedIds = ids.Select(x => int.Parse(x)).OrderBy(x => x));
Sunday, August 21, 2011
Create XSD based on XML file
Sunday, July 31, 2011
Default Field Value at Table Creation Time
Syntax:
Example:
And for an already created table:
[FieldName] type CONSTRAINT [constraint_name] DEFAULT default_value
Example:
CREATE TABLE [Clients]
(
ClientID bigint NOT NULL IDENTITY(1,1) CONSTRAINT [PK_Clients] PRIMARY KEY,
CreatedOn datetime NOT NULL CONSTRAINT [DF_Clients_CreatedOnUtc] DEFAULT GETDATE()
...
)
And for an already created table:
ALTER TABLE Clients
ADD CONSTRAINT [DF_Clients_CreatedOn] DEFAULT GETDATE() FOR CreatedOn
Saturday, July 23, 2011
Unique Fields at Table Creation Time
Sintax:
Example:
Example 2:
[FieldName] type CONSTRAINT [constraint_name] UNIQUE
Example:
CREATE TABLE [Clients]
(
ClientID int NOT NULL IDENTITY(1,1) CONSTRAINT [PK_Clients] PRIMARY KEY,
ServiceCode varchar(50) NOT NULL CONSTRAINT [UQ_Clients_ServiceCode] UNIQUE
...
)
Example 2:
CREATE TABLE [Clients]
(
ClientID int NOT NULL IDENTITY(1,1) CONSTRAINT [PK_Clients] PRIMARY KEY,
ServiceCode varchar(50) NOT NULL,
CONSTRAINT [UN_Clients_Unique] UNIQUE (ClientID, ServiceCode)
...
)
Sunday, July 3, 2011
jQuery ajax function template
Example
Another example
$.ajax({
url: "/Home/Index",
data: { email: email, username: username, etc: etc },
success: function (data) {
debugger; // remove debugger before check-in.
$("#somelabel").text(data.SomeText);
},
type: "POST",
dataType: 'json'
});
Another example
$.ajax(
{
url: "/Account/LogOn",
type: "POST",
dataType: 'json',
data: {
username: $("txtUserName").val(),
password: $("txtPassword").val(),
rememberMe: $("#chkRememberMe").is(':checked')
},
success: function (mydata) {
if(mydata.Success) {
alert(mydata.WelcomeMessage);
}
else{
alert(mydata.Error);
}
}
});
Sunday, June 19, 2011
Get Url - Protocol/Schema, Domain and (if applicable) Port
From goo.gl/WfuVV and goo.gl/AYp9v
It will return a string like the following
Requesr.Url properties and sample values:
Request.Url.GetLeftPart(UriPartial.Authority)
It will return a string like the following
"http://localhost:51528"
Requesr.Url properties and sample values:
Request.Url
{http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com}
AbsolutePath: "/Account/SendForgotPasswordEmail"
AbsoluteUri: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
Authority: "localhost:51528"
DnsSafeHost: "localhost"
Fragment: ""
Host: "localhost"
HostNameType: Dns
IsAbsoluteUri: true
IsDefaultPort: false
IsFile: false
IsLoopback: true
IsUnc: false
LocalPath: "/Account/SendForgotPasswordEmail"
OriginalString: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
PathAndQuery: "/Account/SendForgotPasswordEmail?email=jon@connor.com"
Port: 51528
Query: "?email=jon@connor.com"
Scheme: "http"
Segments: {string[3]}
UserEscaped: false
UserInfo: ""
Subscribe to:
Posts (Atom)