Skip to content

Commit

Permalink
Adding ASP.NET MVC 3 implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mak0t0san committed Jan 11, 2012
1 parent f6eec20 commit 9293906
Show file tree
Hide file tree
Showing 30 changed files with 13,881 additions and 0 deletions.
57 changes: 57 additions & 0 deletions aspnetmvc-3/Content/default.css
@@ -0,0 +1,57 @@
body{
margin:0;
padding:0;
line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}

#maincontainer{
width: 840px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
}

#topsection{
background: #EAEAEA;
height: 90px; /*Height of top section*/
}

#topsection h1{
margin: 0;
padding-top: 15px;
}

#contentwrapper{
float: left;
width: 100%;
}

#contentcolumn{
margin-left: 200px; /*Set left margin to LeftColumnWidth*/
}

#leftcolumn{
float: left;
width: 200px; /*Width of left column*/
margin-left: -840px; /*Set left margin to -(MainContainerWidth)*/
background: #C8FC98;
}

#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}

#footer a{
color: #FFFF80;
}

.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}
20 changes: 20 additions & 0 deletions aspnetmvc-3/Controllers/ProductsController.cs
@@ -0,0 +1,20 @@
namespace mvcapp.Controllers
{
using System.Collections.Generic;
using System.Web.Mvc;

using Models;

public class ProductsController : Controller
{
#region Public Methods

public ActionResult Index(int n)
{
List<Product> products = Service.GetProducts(n);
return View(products);
}

#endregion
}
}
1 change: 1 addition & 0 deletions aspnetmvc-3/Global.asax
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="mvcapp.MvcApplication" Language="C#" %>
40 changes: 40 additions & 0 deletions aspnetmvc-3/Global.asax.cs
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace mvcapp
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

}

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
20 changes: 20 additions & 0 deletions aspnetmvc-3/Models/Category.cs
@@ -0,0 +1,20 @@
namespace mvcapp.Models
{
public class Category
{
#region Constructors and Destructors

public Category(string name)
{
this.Name = name;
}

#endregion

#region Public Properties

public string Name { get; private set; }

#endregion
}
}
32 changes: 32 additions & 0 deletions aspnetmvc-3/Models/Product.cs
@@ -0,0 +1,32 @@
namespace mvcapp.Models
{
using System.Collections.Generic;
using System.Linq;

public class Product
{
#region Constructors and Destructors

public Product(string name, int price, string description, params Category[] categories)
{
this.Name = name;
this.Price = price;
this.Description = description;
this.Categories = categories.ToList();
}

#endregion

#region Public Properties

public List<Category> Categories { get; set; }

public string Description { get; set; }

public string Name { get; set; }

public int Price { get; set; }

#endregion
}
}
48 changes: 48 additions & 0 deletions aspnetmvc-3/Models/Service.cs
@@ -0,0 +1,48 @@
namespace mvcapp.Models
{
using System.Collections.Generic;

public class Service
{
#region Constants and Fields

private static readonly List<Category> categories = new List<Category>();

private static readonly List<Product> products = new List<Product>();

#endregion

#region Constructors and Destructors

static Service()
{
for (var i = 0; i < 5; i++)
{
string name = (1000 + i).ToString();
categories.Add(new Category(name));
}

for (var i = 0; i < 20000; i++)
{
string name = i.ToString();
string description = (i * i).ToString();

var product = new Product(name, i, description);

product.Categories.AddRange(categories);
products.Add(product);
}
}

#endregion

#region Public Methods

public static List<Product> GetProducts(int max)
{
return products.GetRange(0, max);
}

#endregion
}
}
35 changes: 35 additions & 0 deletions aspnetmvc-3/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("mvcapp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("mvcapp")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("edd122e9-baef-4fc2-8edb-9e7c95158d8d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
18 changes: 18 additions & 0 deletions aspnetmvc-3/Views/Products/Index.cshtml
@@ -0,0 +1,18 @@
@{
ViewBag.Title = "Index";
ViewBag.PageName = "Products listing";
}
@model IEnumerable<mvcapp.Models.Product>
<table>
<!-- The products -->
@foreach(var product in Model){
<tr>
<td>
@{Html.RenderPartial("_Product", product);}
</td>
<td>
@string.Join(",", product.Categories.Select(c=> c.Name))
</td>
</tr>
}
</table>
15 changes: 15 additions & 0 deletions aspnetmvc-3/Views/Shared/Error.cshtml
@@ -0,0 +1,15 @@
@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<title>Error</title>
</head>
<body>
<h2>
Sorry, an error occurred while processing your request.
</h2>
</body>
</html>
38 changes: 38 additions & 0 deletions aspnetmvc-3/Views/Shared/_Layout.cshtml
@@ -0,0 +1,38 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="@Url.Content("~/Content/default.css")" media="screen" rel="stylesheet" type="text/css" />

<!-- Title needs to be injected -->
<title>@ViewBag.Title</title>
</head>
<body>
<div id="maincontainer">
<div id="topsection">
<div class="innertube"><h1>Company Title .....</h1></div>
</div>
<div id="contentwrapper">
<div id="contentcolumn">

<!-- Page name needs to be injected -->
<div><h2>@ViewBag.PageName</h2></div>
<div class="innertube">

<!-- The content that is unique for each page -->
@RenderBody()
</div>
</div>
</div>

<div id="leftcolumn">
<div class="innertube">
<h3>Side bar.....</h3>
</div>
</div>

<div id="footer">footer.....</div>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions aspnetmvc-3/Views/Shared/_Product.cshtml
@@ -0,0 +1,6 @@
@model mvcapp.Models.Product

<div class="product">
<img src="@(Model.Name).jpg" />
<span class="productname">@Model.Name</span>, <span class="price">$@Model.Price</span>
</div>

0 comments on commit 9293906

Please sign in to comment.