Custom Validator in Fluent Validation

Fluent validation is an excellent validation framework for and written in .NET. It is easy to use and supports the most common validation scenarios out of the box; I highly recommend that you use it in your projects. There are times, however, that you want to add your own validators in order to support your business rules. In this post, we will be implementing a custom generic validator with arguments.

Scope Inheritance in AngularJS

Scopes in AngularJS use prototypical inheritance. When a child scope tries to access a variable, it first looks for that variable in its own scope. If it doesn't find any, it looks for it in the parent scope, and so on until the $rootScope is reached. This post will illustrate this concept of inheritance in AngularJS.

Validation in Entity Framework Code First

Entity framework code first has support for validation for frequent validation scenarios. In this post, we will look at a couple of ways on how this can be achieved.

If you are new to Entity framework code first, you might want to check out my post on entity framework quick start..

Entity Framework Code First Quick Start

Hi, in this post I will show you how to get started with using Entity Framework.

Automapper Quickstart

Mapping code is ubiquitous in most web applications. The most common use case is when mapping DTO's to business entities or from business entities to view models. Manually writing mapping code, though necessary, is tedious, time-consuming, error prone, and hard to maintain. Fortunately there are libraries such as AutoMapper that help us with the task.

Building a Deployment Package with Static Content

I was once working on a MVC 3 project. The project included the usual web stuff: controllers, views, models, images, css files, and javascript files. There are also a couple of Excel files that we use.

Come deployment time, I followed the steps in building a deployment package. To my surprise (horror), a lot of the css, javascript, and image files were not loaded! Even the Excel files could not be found. So what happened?

Enabling SQL Server Authentication after Installation

If you install SQL Server using the default options, Windows authentication will be enabled and SQL Server authentication will be disabled. This post discusses how to enable SQL Server Authentication after installation and also enable the sa login.

Javascript: Truthy and Falsy Values

I used to wonder what this Javascript code fragment means:

How to Test Internal Methods in Visual Studio

Today I will show a very simple way on how to test internal methods in Visual Studio.

How to Send Email Using C#

Sending email is a useful feature to have in many web applications. For instance, internet marketing strategies often involve using autoresponders to constantly send offers to subscribers. Daily reports can also be emailed to web administrators to keep them updated on the health of their site.

In this post, we will send a simple email using c sharp.

Building a Deployment Package Using Visual Studio 2010

Hi, in this post we will be talking about deployment in general and building a deployment package in Visual Studio 2010 in particular.

From Method to Func

In this post we will take a journey from ordinary methods to the Func. Along the way, we will encounter delegates, anonymous methods and lambda expressions. If any of these concepts are unfamiliar to you, don't worry as they will be explained along the way.

Implementing a Reusable Validation Framework

Validation is an ubiquitous process in all web applications. In this post we will talk about implementing part of a simple validation framework that can be reused in any application.

Centralizing Session Access

Storing and retrieving information from the session state is a common use case in most web applications. For example, user information might be retrieved from the database and then stored in the session upon log in of a user. Following this approach, database calls that retrieve information about a user are reduced (ideally to one call only).

Extension Methods

Extension methods are a way to add functionality (methods) to types that you do not own or that you have no access to. This handy feature was introduced in .NET 3.5.

As an example, consider the following question: in C#, how can you know that an integer is positive? Usually you would do something like this:

Using XML with SQL Server

Sometimes there is a requirement to insert multiple values in the database. This can be done using bulk insert, table-valued functions, through XML, or simply by calling an insert procedure that inserts a single item multiple times. In this post we will be taking a look at how to do multiple inserts using a single query through XML using SQL Server 2008.

Serializing DateTime into JSON

In my current project I ran into the requirement of serializing an object with a DateTime property into Json, specifically through the Json() method of the Controller class. I can't say it serialized pretty well though.

AngularJS: Using ng-repeat

AngularJS is the Javascript MVC framework developed by Google. In this post we will build a simple application using AngularJS. If you aren't familiar with it, you might want to read my introduction to AngularJS first. This post will introduce the concept of controllers and the app will display a simple list of items (persons) to the view.

In this application I will be using AngularJS 1.0.6 which is the latest stable version as of this writing. For the CSS, I am using Twitter bootstrap.

Setting up the Files

First off, here's the barebones html file as well as what it looks like when run:

Resetting the Primary Key of a Table

This quick tip will show how to reset the primary key values for a table in SQL Server:

DBCC CHECKIDENT ([Table], RESEED, [NewCurrentValue])

Where [Table] is the table name and [NewCurrentValue] is the new current value of the id. This would ideally be set to 0, so that the next value (when a row is inserted) will be 1.

Simple Ways to Prevent SQL Injection Attacks

Recently I've been working on a library that would allow direct CRUD operations of any object to the database. The library would detect the types and values of the properties of the classes involved then create Insert, Update, GetAll, and GetById procedures depending on what they find.

It was working great and I was happy with the result. However when I showed it to a friend he pointed out that there might be security concern for building such queries. I researched about it a little and I found he was correct: my code was vulnerable to SQL injection attacks.

Introduction to AngularJS

If you've been reading about javascript frameworks then you're probably seen AngularJS. AngularJS is a javascript framework developed by Google. It supports a MVC pattern and handles two-way data binding between the model and the view. Aside from two-way data binding, it also has support for declaring new html syntax, validation, routing, and more. In this post we will talk about the data binding capability.

Setting Up the Site

First off, we need to have a reference to the AngularJS file, which you can download from here. In this example I downloaded the Uncompressed build of the Stable branch (1.0.6).

How to Read Text Files Using C#

Hello, in this post I will show you how to read text files line-by-line using C#.

Setting Up and Running the Code

Let's say that you have a text file named "test.txt" with the following contents:

I am a simple
text file with
three lines.

We can read the contents of the file using the following code. Note that I am using a console application.

Using Methods With Value and Reference Types

In this post I will show you the practical usage of methods with value types and reference types in C#. I have used a console application to run the code I posted here. It might be helpful if you can also create your own console application so you can try the code samples yourself.

Value and Reference Types in C#

Here is the list of all value types in C#:

  • Structs (ex: System.DateTime)
  • Enums (ex: System.Data.CommandType)
  • Integral types (char, sbyte, byte, short, ushort, int, uint, long, ulong)
  • Float
  • Decimal
  • Double
  • Bool

ASP.NET MVC and QueryString

In this post I will show you how to post and access query string values using ASP.NET MVC 3.

Short Introduction to QueryStrings

A query string is a string that is appended to the end of a URL that follows a specific format.

Using JQuery AJAX GET with ASP.NET MVC JsonResult

Hi, in this post I will show how the client can communicate with the server using AJAX. Specifically, the client will be using the JQuery library, the server will be running on ASP.NET MVC, and the HTTP Method will be GET.

First off, create an MVC project in Visual Studio. I haven't tested MVC 2, but either MVC 3 or MVC 4 should work.

Improving Stringbuilder Performance

In one of our projects we had a requirement to produce a .csv file. In the solution I implemented, I used the StringBuilder class to create the contents of the csv.

It worked great, however it took more than one minute to create the file. What was wrong?