Skip to content

Commit

Permalink
4th session - Implementing backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowf committed Apr 7, 2014
1 parent 704f6bd commit 410753e
Show file tree
Hide file tree
Showing 17 changed files with 554 additions and 5 deletions.
20 changes: 15 additions & 5 deletions meetometer/App/meetingController.ts
Expand Up @@ -7,21 +7,26 @@ module meetometer {

private cancelPromise: ng.IPromise<any>;

public static $inject = ["$scope", "$timeout", "storageService"];
public static $inject = ["$scope", "$http", "$timeout", "storageService"];

constructor(
private $scope: IMeetingScope,
private $http: ng.IHttpService,
private $timeout: ng.ITimeoutService,
private storageService: IStorageService) {

var settings = storageService.getSettings();

$scope.people = settings.people;
$scope.avgSalary = settings.avgSalary;

$scope.meetings = storageService.getMeetings();

$scope.$watch("meetings", () => this.saveMeetings(), true);

$http.get("/api/meetings").success((data) => {
$scope.meetings = data;
});

$scope.$watch("people", () => this.saveSettings());
$scope.$watch("avgSalary", () => this.saveSettings());

Expand Down Expand Up @@ -78,16 +83,21 @@ module meetometer {
}

// post /api/meetings
this.$scope.meetings.push(
new meetingModel(0, new Date(), this.$scope.people, this.$scope.avgSalary, this.$scope.duration));
var meetingToStore =
new meetingModel(0, new Date(), this.$scope.people, this.$scope.avgSalary, this.$scope.duration);
this.$http.post("/api/meetings", meetingToStore).success((data) => {
this.$scope.meetings.push(data);
});

this.reset();
}

deleteMeeting(meetingToDelete: meetingModel) {
var index = this.$scope.meetings.indexOf(meetingToDelete);
if (index > -1) {
this.$scope.meetings.splice(index, 1);
this.$http.delete("/api/meetings?id=" + meetingToDelete.id).success(() => {
this.$scope.meetings.splice(index, 1);
});
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions meetometer/App_Start/UnityConfig.cs
@@ -0,0 +1,39 @@
using System;
using meetometer.Repository;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace meetometer.App_Start
{
/// <summary>
/// Specifies the Unity configuration for the main container.
/// </summary>
public class UnityConfig
{
#region Unity Container
private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() =>
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
});

/// <summary>
/// Gets the configured Unity container.
/// </summary>
public static IUnityContainer GetConfiguredContainer()
{
return container.Value;
}
#endregion

/// <summary>Registers the type mappings with the Unity container.</summary>
/// <param name="container">The unity container to configure.</param>
/// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
/// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<IMeetingRepository, MeetingRepository>();
}
}
}
21 changes: 21 additions & 0 deletions meetometer/App_Start/UnityWebApiActivator.cs
@@ -0,0 +1,21 @@
using System.Web.Http;
using Microsoft.Practices.Unity.WebApi;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(meetometer.App_Start.UnityWebApiActivator), "Start")]

namespace meetometer.App_Start
{
/// <summary>Provides the bootstrapping for integrating Unity with WebApi when it is hosted in ASP.NET</summary>
public static class UnityWebApiActivator
{
/// <summary>Integrates Unity when the application starts.</summary>
public static void Start()
{
// Use UnityHierarchicalDependencyResolver if you want to use a new child container for each IHttpController resolution.
// var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.GetConfiguredContainer());
var resolver = new UnityDependencyResolver(UnityConfig.GetConfiguredContainer());

GlobalConfiguration.Configuration.DependencyResolver = resolver;
}
}
}
21 changes: 21 additions & 0 deletions meetometer/App_Start/WebApiConfig.cs
@@ -0,0 +1,21 @@
using System.Web.Http;

namespace meetometer
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services

// Web API routes
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
36 changes: 36 additions & 0 deletions meetometer/Controllers/MeetingsController.cs
@@ -0,0 +1,36 @@
using System.Web.Http;
using meetometer.Repository;
using meetometer.Repository.Entities;

namespace meetometer.Controllers
{
public class MeetingsController : ApiController
{
private IMeetingRepository repository;

public MeetingsController(IMeetingRepository repository)
{
this.repository = repository;
}

public IHttpActionResult Get()
{
return Ok(repository.GetAll());
}

public IHttpActionResult Post([FromBody] Meeting meeting)
{
return Ok(repository.SaveOrUpdate(meeting));
}

public IHttpActionResult Delete(int id)
{
if (repository.Delete(id))
{
return Ok();
}

return NotFound();
}
}
}
1 change: 1 addition & 0 deletions meetometer/Global.asax
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="meetometer.Global" Language="C#" %>
21 changes: 21 additions & 0 deletions meetometer/Global.asax.cs
@@ -0,0 +1,21 @@
using System;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace meetometer
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configure(WebApiConfig.Register);

var formatters = GlobalConfiguration.Configuration.Formatters;
var jsonFormatter = formatters.JsonFormatter;
var settings = jsonFormatter.SerializerSettings;
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
}
29 changes: 29 additions & 0 deletions meetometer/Migrations/201404071558150_InitialCreate.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions meetometer/Migrations/201404071558150_InitialCreate.cs
@@ -0,0 +1,29 @@
namespace meetometer.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class InitialCreate : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Meetings",
c => new
{
Id = c.Int(nullable: false, identity: true),
Date = c.DateTime(nullable: false),
People = c.Int(nullable: false),
AvgSalary = c.Int(nullable: false),
DurationSeconds = c.Int(nullable: false),
})
.PrimaryKey(t => t.Id);

}

public override void Down()
{
DropTable("dbo.Meetings");
}
}
}
126 changes: 126 additions & 0 deletions meetometer/Migrations/201404071558150_InitialCreate.resx
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Target"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v3MujyUes+GXRjwDK1Y9hPvu0JC6DPagrc29Xpo23RTakFFr4p3GHJBTRfGbAsWSp0ivU7C2ivcrlyWZ3KoFZPf6scS8xBtrQS3kRpeO2f79q8vHJuf4MXf/7L8RAtEUThSP+qdSyKzjfbelhHZAuGJp5OoqE51sV+sO6cHoI4Ga9M0gB+3E/gIqlwRmH3XCX+E93OgO+SuseLpuO/VukMMHsZn2eCb4quDKNhi9v/t6Zu7z+fM/0y/DRHAPAAA=</value>
</data>
<data name="DefaultSchema" xml:space="preserve">
<value>dbo</value>
</data>
</root>

0 comments on commit 410753e

Please sign in to comment.