Skip to content

Commit 8bdaa98

Browse files
committed
Changed page to match standard js JSON format.
1 parent b5875cd commit 8bdaa98

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,37 @@
1-
using System;
2-
using System.Linq;
3-
using System.Configuration;
4-
using System.Collections.Generic;
5-
using ServiceStack.Configuration;
6-
using ServiceStack.OrmLite;
7-
using ServiceStack.ServiceInterface;
8-
using ServiceStack.ServiceInterface.Auth;
9-
using ServiceStack.ServiceInterface.ServiceModel;
10-
using ServiceStack.WebHost.Endpoints;
1+
using ServiceStack.MovieRest.App_Start;
2+
using WebActivator;
113

12-
[assembly: WebActivator.PreApplicationStartMethod(typeof(ServiceStack.MovieRest.App_Start.MovieAppHost), "Start")]
13-
14-
15-
/**
16-
* Entire ServiceStack Starter Template configured with a 'Hello' Web Service and a 'Todo' Rest Service.
17-
*
18-
* Auto-Generated Metadata API page at: /metadata
19-
* See other complete web service examples at: https://github.com/ServiceStack/ServiceStack.Examples
20-
*/
4+
[assembly: PreApplicationStartMethod(typeof (MovieAppHost), "Start")]
215

226
namespace ServiceStack.MovieRest.App_Start
237
{
8+
using Funq;
249
using ServiceStack.Common.Utils;
10+
using ServiceStack.OrmLite;
2511
using ServiceStack.OrmLite.Sqlite;
2612
using ServiceStack.ServiceInterface.Cors;
13+
using ServiceStack.Text;
14+
using ServiceStack.WebHost.Endpoints;
2715

2816
public class MovieAppHost
2917
: AppHostBase
30-
{
18+
{
3119
/// <summary>
3220
/// Initializes a new instance of your ServiceStack application, with the specified name and assembly containing the services.
3321
/// </summary>
3422
public MovieAppHost() : base("ServiceStack REST at the Movies!", typeof (MovieService).Assembly)
3523
{
3624
}
3725

38-
public override void Configure(Funq.Container container)
26+
public override void Configure(Container container)
3927
{
28+
JsConfig.DateHandler = JsonDateHandler.ISO8601;
29+
4030
//Set JSON web services to return idiomatic JSON camelCase properties
41-
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
42-
43-
container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory("~/App_Data/db.sqlite".MapHostAbsolutePath(), SqliteOrmLiteDialectProvider.Instance));
31+
JsConfig.EmitCamelCaseNames = true;
32+
33+
container.Register<IDbConnectionFactory>(
34+
c => new OrmLiteConnectionFactory("~/App_Data/db.sqlite".MapHostAbsolutePath(), SqliteOrmLiteDialectProvider.Instance));
4435

4536
using (var resetMovies = container.Resolve<ResetMoviesService>())
4637
{
@@ -50,16 +41,15 @@ public override void Configure(Funq.Container container)
5041
Plugins.Add(new CorsFeature()); //Enable CORS
5142

5243
SetConfig(new EndpointHostConfig
53-
{
54-
DebugMode = true //Show StackTraces for easier debugging (default auto inferred by Debug/Release builds)
55-
});
44+
{
45+
DebugMode = true //Show StackTraces for easier debugging (default auto inferred by Debug/Release builds)
46+
});
5647
}
5748

58-
5949

6050
public static void Start()
6151
{
6252
new MovieAppHost().Init();
6353
}
6454
}
65-
}
55+
}

src/ServiceStack.MovieRest/Web/default.htm

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,21 @@
8282
var showDetailsForm = function (updateMovie) {
8383
var isUpdate = !!updateMovie;
8484
var newMovie = {
85-
Id: 0,
86-
ImdbId: "tt0110912",
87-
Title: "Pulp Fiction",
88-
Rating: 8.9,
89-
Director: "Quentin Tarantino",
90-
ReleaseDate: new Date(1994, 10, 24),
91-
TagLine: "Girls like me don't make invitations like this to just anyone!",
92-
Genres: ["Crime", "Drama", "Thriller"]
85+
id: 0,
86+
imdbId: "tt0110912",
87+
title: "Pulp Fiction",
88+
rating: 8.9,
89+
director: "Quentin Tarantino",
90+
releaseDate: new Date(1994, 10, 24),
91+
tagLine: "Girls like me don't make invitations like this to just anyone!",
92+
genres: ["Crime", "Drama", "Thriller"]
9393
};
9494

9595
var movie = updateMovie || newMovie;
9696

9797
$("FORM INPUT[type=submit]").val(isUpdate ? "Update movie" : "Add new movie");
9898
var action = "movies";
99-
$("FORM").attr('action', isUpdate ? action + "/" + movie.Id : action);
99+
$("FORM").attr('action', isUpdate ? action + "/" + movie.id : action);
100100
$("FORM").attr('method', isUpdate ? 'PUT' : 'POST');
101101

102102
var title = isUpdate ? "Update " + movie.title : "Add a new movie";
@@ -105,13 +105,14 @@
105105
for (var name in movie) {
106106
$("INPUT[name=" + name + "]").val(movie[name]);
107107
}
108-
108+
109109
if (movie['releaseDate'] != null) {
110-
111-
var date = JSON.parse(movie['releaseDate']);
112-
113-
$("INPUT[name=ReleaseDate]").val(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
110+
var convertedDate = typeof movie['releaseDate'] == "string" ? new Date(movie['releaseDate']) : movie['releaseDate'];
111+
112+
convertedDate = (convertedDate.getFullYear() + "-" + (convertedDate.getMonth() + 1) + "-" + convertedDate.getDate());
113+
$("INPUT[name=releaseDate]").val(convertedDate);
114114
}
115+
115116
$("FORM").fadeIn('fast');
116117
};
117118

@@ -181,35 +182,35 @@ <h2>Existing Movies</h2>
181182
</div>
182183
<form action="movies" method="post">
183184
<h2></h2>
184-
<input type="hidden" name="Id" />
185+
<input type="hidden" name="id" />
185186
<dl>
186187
<dt>Imdb Id</dt>
187188
<dd>
188-
<input type="text" name="ImdbId" />
189+
<input type="text" name="imdbId" />
189190
</dd>
190191
<dt>Title</dt>
191192
<dd>
192-
<input type="text" name="Title" />
193+
<input type="text" name="title" />
193194
</dd>
194195
<dt>Rating</dt>
195196
<dd>
196-
<input type="text" name="Rating" />
197+
<input type="text" name="rating" />
197198
</dd>
198199
<dt>Director</dt>
199200
<dd>
200-
<input type="text" name="Director" />
201+
<input type="text" name="director" />
201202
</dd>
202203
<dt>Release Date</dt>
203204
<dd>
204-
<input type="text" name="ReleaseDate" />
205+
<input type="text" name="releaseDate" />
205206
</dd>
206207
<dt>Tag Line</dt>
207208
<dd>
208-
<input type="text" name="TagLine" />
209+
<input type="text" name="tagLine" />
209210
</dd>
210211
<dt>Genres</dt>
211212
<dd>
212-
<input type="text" name="Genres" />
213+
<input type="text" name="genres" />
213214
</dd>
214215
</dl>
215216
<input type="submit" />

0 commit comments

Comments
 (0)