Entity Framework Video on the Channel 9

Do you know Channel 9? Awesome place to learn about new technologies, there are great videos and one of this is about Entity Framework. Rowan Miller and Diego Vega of the Entity Framework team show us in two videos parts about the concepts of Code First, Database First and Model First. If you are looking for to know more about Entity Framework take a look on this videos:

Visual Studio Toolbox Entity Framework Part 1

Visual Studio Toolbox Entity Framework Part 2

Developer Center – ADO.NET Entity Framework

 

 

 

HTML 5 Game and Loader

This post is only to send you for two websites that I found out about HTML5, the first one is a Game named Cut the Rope, is a great game the was made using HTML5 and CSS3. This is a partner project between Microsoft Internet Explorer’s Team,  ZeptoLab and http://thinkpixellab.com: Game website: http://www.cuttherope.ie/dev

The second website is the PxLoader, it is a javascript library used to load images and sounds that you can use in your HTML5 App, it create a loader for you website, you can load parts of the resources you want, for example, load menu resources first, then load music for second and soon on. PxLoader website: http://thinkpixellab.com/pxloader/

Have fun.. 🙂

 

HOW TO: Sort a GridView using List as a datasource

Hey, A few days ago I had post this : HOW TO: Using sorting on GridView without a DataSourceControl, but it was explaining how make this using DataTable as a datasource. I was doing something in a project, when suddenly 🙂 I need to sort a gridview columns, but my datasource was a ListColletion, like this: List<Costumer>, I made a research found out different ways to make the sort works. But the simplest way is this one:


private string ConvertSortDirectionToSql(SortDirection sortDirection)
{

string newSortDirection = string.Empty;

switch (sortDirection) {
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}

protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{

string previousSortExpression=(string)ViewState["previousGVSortKey"];
string sortExpression=e.SortExpression;
SortDirection sortDirection = e.SortDirection;

if (sortExpression.Equals(previousSortExpression))
{
sortDirection = SortDirection.Descending;
ViewState["previousGVSortKey"] = string.Empty;
}
else {
ViewState["previousGVSortKey"] = sortExpression;
}

     List<Costumer> list = (List<Costumer>)GridView.DataSource;
     if (list.Count > 0) {
        var query = from c in list
                    select c;

           if (sortDirection == SortDirection.Ascending)
{
if (sortExpression == "FIRST_NAME")
query=query.OrderBy(c => c.FirstName);

if (sortExpression == "LAST_NAME")
query=query.OrderBy(c => c.LastName);

if (sortExpression == "EMAIL")
query = query.OrderBy(c => c.Email);

if (sortExpression == "ADDRESS")
query = query.OrderBy(c => c.Address);
}
else {
if (sortExpression == "FIRST_NAME")
query = query.OrderByDescending(c => c.FirstName);

if (sortExpression == "LAST_NAME")
query = query.OrderByDescending(c => c.LastName);

if (sortExpression == "EMAIL")
query = query.OrderByDescending(c => c.Email);

if (sortExpression == "ADDRESS")
query = query.OrderByDescending(c => c.Address);
}

GridView.DataSource = query.ToList();
GridView.DataBind();
     }
}

I know there are a lot of better way to do that, but for now it is working, maybe I’ll try to make something better.

Exposing a property on the master page to child page

Sometimes, when we are using master pages, we have the necessity to access some information that is available “only” on the Master Page, there are a few ways you can expose this information to child pages access them. One way is through Property, lets say that you have on the master page the string attribute  called _userName, but in your child page you need this UserName too, so you can create an property on the MasterPage that return this attribute. This way on the child page we can call this property like this, Master.UserName, only don’t forget to set the directive MasterType in your child page, set the value VirtualPath with the path of you master page.

Master Page


public partial class MyMasterPage : System.Web.UI.MasterPage
{
public virtual string UserName { get {return this._userName;} }
private string _userName;

protected void Page_Init(Object sender, EventArgs e)
{
this._userName= "Douglas";
}
}

MyChild.aspx

<%@ Page Title="MyChild" Language="C#" MasterPageFile="~/Master/MyMasterPage.Master"
AutoEventWireup="true" CodeBehind="MyChild.aspx.cs" Inherits="MyChild" %>
<%@ MasterType VirtualPath="~/Master/MyMasterPage.Master" %>

MyChild.aspx.cs (Code Behind)

public partial class MyChild: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
labelUserName.Text=Master.UserName;
}
}

Reference: http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx

Learn JavaScript having fun…

Today I found out an awesome website http://www.codecademy.com, It teach JavaScript like a game, I stared doing the first lesson and I can’t stop until finish the whole 8 lessons for the first module. I already know JavaScript for a long time, but I think you can take a look in this website, I think in the future will be more courses, I think this website will grow up faster, the idea is great.

Code Academy:

http://www.codecademy.com

Course 1: Getting Started with Programming

Course 2: JavaScript Quick Start Guide

Course 3: Functions in Javascript

Using Forms Authentication. SetAuthCookie

I know, it’s old :-), but just to keep this information available for someone, when you are using the  FormsAuthentication.Authenticate(login, password) the authentication cookie/ticket is created automatically to make sure that the user is authenticated, but sometimes you have your own login form, your own authenticate method, so you need to call the method FormsAuthentication.SetAuthCookie(value, bool) to create the cookie/ticket for the authenticate user.

If you are using the Authentication mode to Forms and when you call this method (HttpContext.Current.User.Identity.IsAuthenticated) to verify if the user is Authenticated, will be true only if exists an authentication ticket cookie (I belive can be through Cookie or SqlAuthCookie).

You can find more explanation about this in the follows links:

Explained: Forms Authentication in ASP.NET 2.0

http://msdn.microsoft.com/en-us/library/ff647070.aspx

How To: Use Forms Authentication with SQL Server in ASP.NET 2.0

http://msdn.microsoft.com/en-us/library/ms998317.aspx

Nested classes to structuring Unit tests approach

I had read a great post in the Phil Haack blog, you can access here (Structuring Unit Tests) about how you can organize your unit tests, making a nested class for each method that you going to write, it is strange when you hear this, but after you understand this principle, I think you going to agree with this approach. It is a better idea to organize your unit test class, to find faster you test methods. Who write unit test know that sometimes you feel a little lost between a lot of methods and classes.

Take a look:

Structuring Unit Tests