Skip to content

Commit 266ecd5

Browse files
author
Tharindu Abeygunawardana
committed
Add google maps view on home page
1 parent d644201 commit 266ecd5

File tree

9 files changed

+86
-63
lines changed

9 files changed

+86
-63
lines changed

Ndot/Bootstrapper.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Web.Http;
2+
using System.Web.Mvc;
23
using Microsoft.Practices.EnterpriseLibrary.Logging;
34
using Microsoft.Practices.Unity;
45
using MongoRepository;
56
using Ndot.Helpers;
67
using Ndot.Models;
8+
using Unity.Mvc4;
79

810
namespace Ndot
911
{
@@ -14,6 +16,7 @@ public static void Initialise()
1416
var container = BuildUnityContainer();
1517

1618
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
19+
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
1720
}
1821

1922
private static IUnityContainer BuildUnityContainer()

Ndot/Content/Site.css

+4
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,7 @@ tr.pager td {
754754
margin: 0;
755755
}
756756
}
757+
758+
#map-canvas {
759+
height: 100%;
760+
}

Ndot/Controllers/HomeController.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Device.Location;
34
using System.Linq;
45
using System.Web;
56
using System.Web.Mvc;
7+
using MongoRepository;
8+
using Ndot.Models;
69

710
namespace Ndot.Controllers
811
{
912
public class HomeController : Controller
1013
{
14+
private readonly IRepository<Sr1FormData> _repository;
15+
16+
public HomeController(IRepository<Sr1FormData> repository)
17+
{
18+
_repository = repository;
19+
}
20+
1121
public ActionResult Index()
1222
{
13-
return View();
23+
var results = _repository.Collection.FindAllAs<Sr1FormData>().ToList();
24+
return View(results);
1425
}
1526
}
1627
}

Ndot/Models/DomainObjects.cs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Sr1FormData : Entity
3939
public string Street { get; set; }
4040
public string City { get; set; }
4141
public string County { get; set; }
42+
public double Latitude { get; set; }
43+
public double Longitude { get; set; }
4244
public DateTime CreatedDate { get; set; }
4345
public List<Actor> Actors { get; set; }
4446
}

Ndot/Ndot.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Reference Include="System" />
7575
<Reference Include="System.Data" />
7676
<Reference Include="System.Data.Entity" />
77+
<Reference Include="System.Device" />
7778
<Reference Include="System.Drawing" />
7879
<Reference Include="System.Web.Entity" />
7980
<Reference Include="System.Web.ApplicationServices" />
@@ -163,6 +164,9 @@
163164
<Private>True</Private>
164165
<HintPath>..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
165166
</Reference>
167+
<Reference Include="Unity.Mvc4">
168+
<HintPath>..\packages\Unity.Mvc4.1.2.0.0\lib\net40\Unity.Mvc4.dll</HintPath>
169+
</Reference>
166170
<Reference Include="Unity.WebApi">
167171
<HintPath>..\packages\Unity.WebAPI.0.10\lib\net40\Unity.WebApi.dll</HintPath>
168172
</Reference>
@@ -209,11 +213,9 @@
209213
<Compile Include="Global.asax.cs">
210214
<DependentUpon>Global.asax</DependentUpon>
211215
</Compile>
212-
<Compile Include="Helpers\DebugTextWriter.cs" />
213216
<Compile Include="Helpers\DlBarCodeParser.cs" />
214217
<Compile Include="Helpers\IEdmundsApiAgent.cs" />
215218
<Compile Include="Helpers\ILogger.cs" />
216-
<Compile Include="Helpers\ObjectDumper.cs" />
217219
<Compile Include="MessageHandlers\BasicAuthMessageHandler.cs" />
218220
<Compile Include="Models\DomainObjects.cs" />
219221
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -304,6 +306,7 @@
304306
<Content Include="Scripts\knockout-2.2.0.debug.js" />
305307
<Content Include="Scripts\knockout-2.2.0.js" />
306308
<Content Include="Scripts\modernizr-2.6.2.js" />
309+
<Content Include="Unity.Mvc4.README.txt" />
307310
<Content Include="Unity.WebAPI.README.txt" />
308311
<Content Include="Web.config">
309312
<SubType>Designer</SubType>

Ndot/Unity.Mvc4.README.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Getting started with Unity.Mvc4
2+
-------------------------------
3+
4+
To get started, just add a call to Bootstrapper.Initialise() in the Application_Start method of Global.asax.cs
5+
and the MVC framework will then use the Unity.Mvc4 DependencyResolver to resolve your components.
6+
7+
There is code in the bootstrapper to initialise the Unity container. Any components that you need to inject should be
8+
registered in the BuildUnityContainer method of the Bootstrapper. All components that implement IDisposable should be
9+
registered with the HierarchicalLifetimeManager to ensure that theey are properly disposed at the end of the request.
10+
11+
It is typically not necessary to register your controllers with Unity.
12+
13+
The readme has been copyied from Unity.MVC3 as this is a package just to support MVC4, the unity portion is identical.
14+
You can find out more about Unity.Mvc3 by visiting:
15+
16+
http://devtrends.co.uk/blog/introducing-the-unity.mvc3-nuget-package-to-reconcile-mvc3-unity-and-idisposable

Ndot/Views/Home/Index.cshtml

+40-44
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
<div id="body">
2-
<section class="featured">
3-
<div class="content-wrapper">
4-
<hgroup class="title">
5-
<h1>Welcome to ASP.NET Web API!</h1>
6-
<h2>Modify the code in this template to jump-start your ASP.NET Web API development.</h2>
7-
</hgroup>
8-
<p>
9-
ASP.NET Web API allows you to expose your applications, data and services to the
10-
web directly over HTTP.
11-
</p>
12-
<p>
13-
To learn more about ASP.NET Web API visit the
14-
<a href="http://go.microsoft.com/fwlink/?LinkID=238195" title="ASP.NET Web API Website">ASP.NET Web API Website</a>.
15-
The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET Web API.
16-
If you have any questions about ASP.NET Web API, visit
17-
<a href="http://go.microsoft.com/fwlink/?LinkID=238196" title="ASP.NET Web API Forum">our forums</a>.
18-
</p>
19-
</div>
20-
</section>
21-
<section class="content-wrapper main-content clear-fix">
22-
<h3>We suggest the following steps:</h3>
23-
<ol class="round">
24-
<li class="one">
25-
<h5>Getting Started</h5>
26-
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach
27-
a broad range of clients, including browsers and mobile devices. ASP.NET Web API
28-
is an ideal platform for building RESTful applications on the .NET Framework.
29-
<a href="http://go.microsoft.com/fwlink/?LinkId=245160">Learn more…</a>
30-
</li>
1+
@model List<Ndot.Models.Sr1FormData>
2+
3+
<div id="map-canvas" />
4+
5+
6+
7+
@section HeadScripts {
8+
<script type="text/javascript"
9+
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDUqiIvhxiT8znW80ZnJckV78B3zftp0mQ&sensor=false">
10+
</script>
11+
12+
<script type="text/javascript">
13+
function initialize() {
14+
var mapOptions = {
15+
center: new google.maps.LatLng(36.106364, -115.138871),
16+
zoom: 12
17+
};
18+
var map = new google.maps.Map(document.getElementById("map-canvas"),
19+
mapOptions);
20+
21+
@foreach (var sr1Form in Model)
22+
{
23+
<text>
24+
var marker = new google.maps.Marker({
25+
position: new google.maps.LatLng(@sr1Form.Latitude, @sr1Form.Longitude),
26+
title: "@sr1Form.Street"
27+
});
28+
marker.setMap(map);
29+
</text>
30+
}
31+
}
32+
google.maps.event.addDomListener(window, 'load', initialize);
33+
</script>
34+
35+
<style type="text/css">
36+
html { height: 100% }
37+
body { height: 100%; margin: 0; padding: 0 }
38+
</style>
39+
40+
}
3141

32-
<li class="two">
33-
<h5>Add NuGet packages and jump-start your coding</h5>
34-
NuGet makes it easy to install and update free libraries and tools.
35-
<a href="http://go.microsoft.com/fwlink/?LinkId=245161">Learn more…</a>
36-
</li>
37-
<li class="three">
38-
<h5>Find Web Hosting</h5>
39-
You can easily find a web hosting company that offers the right mix of features
40-
and price for your applications.
41-
<a href="http://go.microsoft.com/fwlink/?LinkId=245164">Learn more…</a>
42-
</li>
43-
</ol>
44-
</section>
45-
</div>

Ndot/Views/Shared/_Layout.cshtml

+3-16
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,11 @@
66
<title>@ViewBag.Title</title>
77
@Styles.Render("~/Content/css")
88
@Scripts.Render("~/bundles/modernizr")
9+
10+
@RenderSection("HeadScripts", required: false)
911
</head>
1012
<body>
11-
<header>
12-
<div class="content-wrapper">
13-
<div class="float-left">
14-
<p class="site-title">
15-
<a href="~/">ASP.NET Web API</a></p>
16-
</div>
17-
<div class="float-right">
18-
<nav>
19-
<ul id="menu">
20-
<li>@Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)</li>
21-
<li>@Html.ActionLink("API", "Index", "Help", new { area = "" }, null)</li>
22-
</ul>
23-
</nav>
24-
</div>
25-
</div>
26-
</header>
13+
2714
@RenderBody()
2815

2916
@Scripts.Render("~/bundles/jquery")

Ndot/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
3838
<package id="System.Spatial" version="5.2.0" targetFramework="net45" />
3939
<package id="Unity" version="2.1.505.2" targetFramework="net45" />
40+
<package id="Unity.Mvc4" version="1.2.0.0" targetFramework="net45" />
4041
<package id="Unity.WebAPI" version="0.10" targetFramework="net45" />
4142
<package id="WebGrease" version="1.3.0" targetFramework="net45" />
4243
<package id="ZXing.Net" version="0.12.0.0" targetFramework="net45" />

0 commit comments

Comments
 (0)