Sample mvc application Part II

December 7, 2010

In previous part we have seen the functional detail about the system.
Where we have seen application contains number of contain pages.To managed these contain pages in application is very important.

To manage content page, there are different approaches and readymade controls available in market. But more powerful and suitable way is Jquery’s CKEditor core script.

We will see how to create content page using Jquery’s CKEditor.

1.Download the latest CKEditor files from here

2.Add JQuery links into master page

3.Now create an textarea in view

Html.TextArea(“chText”, “”)

4.Now add the following JavaScript code in view

$(function(e) {
CKEDITOR.replace(‘chText’);
});

5. That’s it! Execute the page and you can see the CKEditor in action. We can modify the contain page or create new contain page using this editor.

Sample MVC application

November 30, 2010

This application is simple framework to setup the e-comers sites for small business vendors.

Small business vendors can easily setup their e-comers site by running simple wizard and by providing the details about site and product.

Vendor can choose there colors, themes, logo, color template, e-mail template and other detail from existing set of list and make the site more customized for them.

Site features:-

Site is divided into eight parts. Different parts are representing as menu as described below.

1. Site: – Site setup wizard, Generals, color and Template are the menu under site which will help to setup the site appearance and layouts of site.

2. Content: – This menu helps us to manage the site content and it is further classified into below parts

  • Pages: – This option is used to create pages for site. Site will provide the page editor; we can select the existing Page container, page Blocks, page designer and HTML template to customize the site page.  
  • Content:-Content option helps us to create blog, “On line help” and Forums like FAQ for the existing site.

3. Store:-Configuration, Payment, shipping and tax will be sub menu under Store.

I Configuration: – Under configuration option use can configure the site registration information and product information.

II Payment: – Vendor can setup all the possible Payment channels that site are supporting. End user can select this appropriate mode for their payments. Possible payment modes supported by system are: 

  • Pay Pal express,
  • Pay Pal standard,
  • Credit card
  • Google checkout
  • Offline payment

III. Shipping: – This menu will setup the different mode of shipping that end user can utilize. Possible shipping modes supported by system are:

  • Custom shipping table,
  • FedEx real time rates
  • UPS Real Time rates
  • USPS real time rates

4. Catalog:-Catalogs deal with products and type of products that vendor is going to provide for end users.

  • · This will help to add new product along with information like manufacturer, price, shipping type, weight and product images and more information about products etc.
  • · It has also option to create new category. Category is group, under which main product are divided. This will help end user to identify the products

5. User: – Various users and their role are managed under the user section. Administrator can manage the user creation, modification and deletion.  Site will also have provision to provide the discount base on order amount.

6. Orders:-Under order menu we can see the order details and order history; we can also alter the order by removing item and adding new items

7. Promotions: – Activity to promote the sell is done under the Promotions menu. All possible promotion modes are:

  • Coupon:-Coupes are provided to end user based on order amount and period.
  • GiftCertificate: – Site administrator can provide the Gift certificate by selecting this option.  
  • · Email Campaigns’:- Site administrator can communicate to end user about the products through email using email campaigns menu.

8. Reports: – Site provides the following list of reports to manage the business.

  • Who is Online
  • User Tracker
  • Sales Report
  • Product Report

Decorator pattern

October 31, 2010

The decorator pattern extends the functionality of individual objects by wrapping them with one or more decorator classes. These decorators can modify existing members and add new methods and properties at run-time.

Where to use it:-
The Decorator pattern is extremely useful when you want to add extra functionality to existing classes,But you don’t want to be tied up to a specific implementation.

C# Code

public interface IPrice

{

decimal Cost { get; set; }

}

public class Product

{

public IPrice Price { get; set; }

}

public class BasePrice : IPrice
{
private Decimal _cost;
public decimal Cost
{
get { return _cost; }
set { _cost = value; }
}
}

Wrapper Class /decorator  class

public class CurrencyPriceDecorator : IPrice
{

private IPrice _basePrice;

private decimal _exchangeRate;

public CurrencyPriceDecorator(IPrice price, decimal exchangeRate)
{

_basePrice = price;

_exchangeRate = exchangeRate;

}

public decimal Cost

{

get { return _basePrice.Cost * _exchangeRate; }

set { _basePrice.Cost = value;}

}

}

This pattern promotes to create new derived class instead of modifying the existing object.   This way this pattern supports OCP principle

ASP.NET profile

October 24, 2010

Profile: -ASP.NET profile service allows us to maintain the user
specific information.

User specific information includes favorite URLS, background
colors, themes, user settings and etc.

Provider services offer varios API’s to access and manage the user information from database.

How to set profile service:-

To activate the profile service, we need to specify “Profile” and “Provider” tag in configuration file. These tags will create classes at runtime and will perform task like storing and retrieving the user information from database.

1. Add <profile> element with a <provider> element defining the provider used to store and retrieve user-specific data.

<profile>
<providers>
<add name=”AspNetSqlProfileProvider”
connectionStringName=”LocalSqlServer”
applicationName=”/”
type=”System.Web.Profile.SqlProfileProvider,
System.Web, Version=2.0.0.0,Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a”/>

</providers>
</profile>

It is not mandatory to set provider detail. ASP.NET profile service will automatically create SQL express database and will store the property. But If want to use customize provider then we have to specifying configuration details.

2. Add a <properties> element and an <add> element for each user-specific data item that need to be included in the profile.

<profile>
<properties>
<add name=”FirstName”/>
<add name=”LastName”/>
<add name=”Age”/>
<add name=”City”/>
</properties>
</profile>

We can define the list of properties inside <properties> tag configuration file that we need to maintain.

Providers:-

ASP.NET 2.0 has default provider to handle the storage and retrieval of the user profile data.

The SqlProfileProvider supports storing the user profile information in SQL Express, SQL Server 7.0, SQL Server 2000, or SQL Server 2005 without requiring you to write any code.

All that is required is to add <providers> element and <profile> element in web.config.

Provider service will store all profile related information in aspnet_Profile table of ASPNETDB.MDF database.

SqlProfileProvider attributes

Name: – Defines the name for the provider.It can be any relevant value

Type: – Specifies the type of the property. Use the “class, assembly” notation in case of user-defined System.Web.Profile.SqlProfileProvider for the SqlProfileProvider.

ConnectionStringName: – Specifies the name of the connection string used to access the SQL database.

applicationName:- Specifies the name of the application using the profile provider. The default value is the value of the system.Web.HttpRequest.ApplicationPath property.

(Application name is value specified for the applicationNameattribute in the configuration file for the Webapplication; if it is not set we can set ApplicationVirtualPath value is used for ASP.NET applications.)

Properties attribute:-

Name: – This attribute specifies the name of the property in the dynamically created Profile class. The name property must be unique.

Type:-This attribute specifies the data type of property. The type can be any .NET data type or any custom data type. But data type must be serialized.

SerializeAs: – This property describes how data is serialized & storage in the database. Valid values are String, Xml, Binary, and ProviderSpecific

AllowAnonymous :– This attributes specifies if the property should be allowed to access anonymous users. Valid values are true and false ,The default value is false.

Provider:-This attribute specifies the profile provider to be used to persist the property data. We can specify different provides to persist the data of individual properties.

defaultValue:-Specifies the default value used when no profile data is available for the property. This value is not stored in the data store by default. It is used to initialize the property in the Profile object only.

readOnly:- Specifies if the property should be read-only. Valid values are True and false. The default value is false.

Profile page operation:-
We can directly access the defined properties through the ASP.NET profile object. ASP.NET profile service stores the profile object into database and makes it available after every page request.

Read values:- We can access the profile object property easily
e.g.:-
Label1.Text= “Profile stored successfully!<br/>” +
“<br/>First Name: ” + Profile.FirstName +
“<br/>Last Name: ” + Profile.LastName +
“<br/>Age: ” + Profile.Age +
“<br/>City: ” + Profile.City;

Write values:- By setting profile properties values will be automatically maintained over page round trips.

Profile.FirstName = TextBox1.Text;
Profile.LastName = TextBox2.Text;
Profile.Age = TextBox3.Text;
Profile.City = TextBox4.Text

Groupings: – We can create a hierarchy of profile properties using the group
element. Grouping allows us to categorize properties.
profile.Name= “scott”;
Profile.UI.Theme = “Reddish”;
Profile.UI.MasterPage= “layout.master”;

Configuration for group Property:-
<properties>
<add name=”Name”/>
<add name=”age”/>
<group name=”AutomobilePreferences”>
<add name=”CarModels” type=”System.Collections.ArrayList”/>
<add name=”PricePoint” type=”int” defaultValue=”18500″/>
</group>
</properties>

Custom profile classes: –

We can create our own class to handle the profile data instead of configuring the property in provider tag. This custom class has three specific requirements.

1. It must be inherited from profileBase.

2. Class must be serializable

3. The class must include a property for each user profile data item to be stored

At same time we have to set <profile> elements inherits attributes with the fully qualified namespace of custom profile class.

Example of Custom Class:-

1. Custom class definition example:-
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Profile;
public class UserDefinedProfileClass : ProfileBase
{
public UserDefinedProfileClass() {}
public List<String> JunkFood
{

get { return (list<String>)base[“JunkFood”]; }

set { base[“JunkFood”] =value; }
}
}

2. Setting inherit attributes of profile tag in configuration file

<profile enabled=”true” defaultProvider=”MyProfileSqlProvider” inherits=”UserDefinedProfileClass”>
<providers>

<add name=”MyProfileSqlProvider” type=”System.Web.Profile.SqlProfileProvider,
System.Web, Version=2.0.3600.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”ASPNETDB” applicationName=”ProfileQuickStart”/>
</providers>

</profile>

Advantage of custom class:-
1.) We can use the same user profile data in multiple applications.
2.) It save the maintenance problem

Anonymous user profile – By default authenticated user is only eligible
to access the profile properties. However ASP.NET profile supports anonymous
users by configuring below setting

1.Add an <anonymousIdentification> element to enable the anonymous identification features and to define the cookie used to identify the user.

2. Set the allowAnonymous attribute of each profile property that is to be persisted for anonymous users to true.

When anonymous identification is enabled ASP.NET 2.0 generates
the GUID and use that ID for identification for all visitors to the application.

On every first visit GUID is generated and stored in cookies and that is persisted on
user’s computer.

For all subsequent requests, the cookies are retrieved and GUID is used to access his/her profile information.

<anonymousIdentification enabled=”true”
cookieName=”MyAppCookies”
cookiePath=”/”
cookieRequireSSL=”false”
cookieTimeout=”525600″
cookieSlidingExpiration=”true”
cookieProtection=”All”

/>
<profile enabled=”true” defaultProvider=” MyqlRoleProvider” automaticSaveEnabled=”false” >
<providers>

<add name=”MyqlRoleProvider” type=”System.Web.Security.SqlRoleProvider” connectionStringName=”sqlConnectionString” applicationName=”” />

</providers>
<properties>
<add name=”FirstName”type=”System.String”
serializeAs=”String”
allowAnonymous=”true”
provider=”MyqlRoleProvider”
defaultValue=””
readOnly=”false” />
<add name=”LastName”
type=”System.String”
serializeAs=”String”
allowAnonymous=”true”
provider=”MyqlRoleProvider ”
defaultValue=””
readOnly=”false” />
</properties>
</profile>

anonymousIdentification element attributes

enabled:- It indicates the HttpAnonymousIdentificationModule is enable the default value is true.

cookieName:- Name of cookies used to store the anonymous ID of user. The default is .ASPXANONYMOUS.

cookiesPath:- Defines the path to directory where cookies are stored. Unless your application requires specifying the path otherwise leave the path as “/”.

cookiesRequiresSSL:- Define whether an SSL connection is required to transmit the cookies to client. The default value is false.

cookiesTimeout:- Specifies the cookie expiration time in minutes.

cookiesSlidingExpiration:- Defines if sliding expiration of the cookie is enabled. If set to True, the cookie time to expire will be refreshed on every page request. If set to false,the cookie will expire at the time set when the cookie was created. The default value is true

cookiesProtection:- Defines the protection method used for the
cookie. Possible values are All, None, Encryption, and Validation. Validation specifies that the cookie data will be validated to ensure it was not altered in transit. Encryption specifies that the cookie is encrypted

While designing the web Pages, CSS base design is better then table base.

October 16, 2010

See the list of difference which proves the CSS is better….than tables.

  • When we are using table for layout design then we are mixing presentation with content, so your bandwidth usage is higher than need. Also page visitors have to download the same contains for every request.
  • if you want to change the layout of a table site, you have to change your tables in every single one of your pages. Not a nice job. With a full CSS site, all you need do is change that one CSS file.
  • Tables really don’t help accessibility for viewers with disabilities
  • Likewise, people visiting your site using PDAs, mobile phones, and the like do not have the screen space that your big flashy table layout demands. A well written CSS site will generally scale far better to smaller and larger screens than a comparable table layout will.
  • Tables can hurt search engine ratings. If you’re using a “classic” left hand navigation table, your navigation will be placed before your content in your HTML file. Because Search Engines generally place more importance on the things nearer the beginning of a page, the chances are your content will be largely ignored.
  • Tables can take longer to display correctly than CSS. If you use Internet Explorer, you’ll have seen this many times when loading tabled sites. While everything on the page is downloading, the IE will keep retendering, bouncing the contents of the page back and forth until the download is complete and it knows where to place everything.
  • Properly laying out a page requires specifying all kinds of details such as margins, text alignment and so forth. Using tables, you have to specify all this stuff right in the tags, resulting in labyrinthine code that often takes up far more space than the page’s contents.
  • Absolute positioning, is difficult with tables, is an instant with CSS.

Hello world!

October 14, 2010

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!