Commit 8206a023 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+7 −0
Changes for Learning C Sharp Best Practices - Working Files/Chapter 1/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+22 −0
Changes for Learning C Sharp Best Practices - Working Files/Chapter 2/LinqQueries/LinqQueries.sln: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Web
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqQueries", "LinqQueries\LinqQueries.csproj", "{FDD6837C-2F52-428D-B631-923FD325C0CD}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{FDD6837C-2F52-428D-B631-923FD325C0CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{FDD6837C-2F52-428D-B631-923FD325C0CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{FDD6837C-2F52-428D-B631-923FD325C0CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{FDD6837C-2F52-428D-B631-923FD325C0CD}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal
+23 −0
Changes for Learning C Sharp Best Practices - Working Files/Chapter 2/LinqQueries/LinqQueries/App_Start/RouteConfig.cs: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}
+72 −0
Changes for Learning C Sharp Best Practices - Working Files/Chapter 2/LinqQueries/LinqQueries/Controllers/HomeController.cs: 72 added lines, 0 removed lines.
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using LinqQueries.Models;

namespace LinqQueries.Controllers
{
    public class HomeController : Controller
    {
        private NorthwindEntities db = new NorthwindEntities();

        public ActionResult Index()
        {
            // basic select with where clause
            //var products = db.Products.Where(p => p.UnitPrice > 50M).Select(p => p);

            // order by
            //var products = db.Products.OrderByDescending(p => p.UnitPrice);

            // take
            var products = db.Products.OrderByDescending(p => p.UnitPrice).Take(5);

            return View(products.ToList());
        }

        public ActionResult Categories()
        {
            // select distinct
            var categories = db.Products.Select(p => p.CategoryID).Distinct();

            // count
            ViewBag.CategoryCount = db.Products.Select(p => p.CategoryID).Distinct().Count();

            return View(categories.ToList());
        }

        public ActionResult Orders()
        {
            // join
            var orders = from c in db.Customers
                         join o in db.Orders
                         on c.CustomerID equals o.CustomerID
                         where o.Freight > 25M
                         orderby o.Freight descending
                         select new JoinedOrder()
                         {
                             OrderID = o.OrderID,
                             CustomerID = o.CustomerID,
                             CompanyName = c.CompanyName,
                             ContactName = c.ContactName,
                             Freight = o.Freight,
                             ShipVia = o.ShipVia
                         };

            return View(orders.ToList());
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
+1 −0
Changes for Learning C Sharp Best Practices - Working Files/Chapter 2/LinqQueries/LinqQueries/Global.asax: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
<%@ Application Codebehind="Global.asax.cs" Inherits="LinqQueries.MvcApplication" Language="C#" %>
Loading