Skip to content

Commit 0d3da3e

Browse files
SNEK Sample
1 parent e2d13b0 commit 0d3da3e

36 files changed

+1909
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ _UpgradeReport_Files/
129129
Backup*/
130130
UpgradeLog*.XML
131131
/OWinWebApiOData/Scripts/typings
132+
/Snek2015AngularWebApiSample/WebClient/Content
133+
/Snek2015AngularWebApiSample/WebClient/fonts
134+
/Snek2015AngularWebApiSample/WebClient/scripts
1 Byte
Binary file not shown.

ProfilingWorkshop/PiWithMonteCarlo/PiWithMonteCarlo.sln

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30723.0
4+
VisualStudioVersion = 12.0.31101.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PiWithMonteCarlo", "PiWithMonteCarlo\PiWithMonteCarlo.csproj", "{49B1C64D-9B7C-4B1E-983E-65B47F642B03}"
77
EndProject
@@ -55,7 +55,4 @@ Global
5555
GlobalSection(SolutionProperties) = preSolution
5656
HideSolutionNode = FALSE
5757
EndGlobalSection
58-
GlobalSection(Performance) = preSolution
59-
HasPerformanceSessions = true
60-
EndGlobalSection
6158
EndGlobal
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "WebApi\WebApi.csproj", "{6CC8747E-202D-41CF-B408-BDE41EE8303D}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebClient", "WebClient\WebClient.csproj", "{4D0F837A-5C0D-4DB3-A6DE-18AF592B96E1}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{6CC8747E-202D-41CF-B408-BDE41EE8303D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{6CC8747E-202D-41CF-B408-BDE41EE8303D}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{6CC8747E-202D-41CF-B408-BDE41EE8303D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{6CC8747E-202D-41CF-B408-BDE41EE8303D}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{4D0F837A-5C0D-4DB3-A6DE-18AF592B96E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{4D0F837A-5C0D-4DB3-A6DE-18AF592B96E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{4D0F837A-5C0D-4DB3-A6DE-18AF592B96E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{4D0F837A-5C0D-4DB3-A6DE-18AF592B96E1}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using System.Data.Entity;
3+
using System.Threading.Tasks;
4+
using System.Web.Http;
5+
using System.Linq;
6+
using System;
7+
8+
namespace WebApi.Controller
9+
{
10+
public class RatingController : ApiController
11+
{
12+
[Route("api/ratings")]
13+
[HttpPost]
14+
public async Task<IHttpActionResult> StoreRatings([FromBody]IEnumerable<SessionRatingDto> ratings)
15+
{
16+
using (var context = new ConferenceContext())
17+
{
18+
foreach (var rating in ratings.Where(r => r.Rating > 0))
19+
{
20+
var existingRating = await context.Ratings.Include("Ticket").Include("Session").FirstOrDefaultAsync(
21+
rate => rate.Ticket.TicketId == rating.TicketId && rate.Session.SessionId == rating.SessionId);
22+
if (existingRating == null)
23+
{
24+
var ticket = await context.Tickets.FirstOrDefaultAsync(t => t.TicketId == rating.TicketId);
25+
var session = await context.Sessions.FirstOrDefaultAsync(s => s.SessionId == rating.SessionId);
26+
27+
var newRating = new SessionRating() { Ticket = ticket, Session = session, Rating = rating.Rating };
28+
context.Ratings.Add(newRating);
29+
}
30+
else
31+
{
32+
existingRating.Rating = rating.Rating;
33+
context.Entry(existingRating).State = EntityState.Modified;
34+
}
35+
36+
await context.SaveChangesAsync();
37+
}
38+
}
39+
40+
return this.Ok();
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using System.Data.Entity;
3+
using System.Threading.Tasks;
4+
using System.Web.Http;
5+
6+
namespace WebApi.Controller
7+
{
8+
public class SessionController : ApiController
9+
{
10+
[Route("api/sessions")]
11+
[HttpGet]
12+
public async Task<IHttpActionResult> GetSessions()
13+
{
14+
using (var context = new ConferenceContext())
15+
{
16+
var sessions = await context.Sessions.ToArrayAsync();
17+
if (sessions.Length == 0)
18+
{
19+
return this.NotFound();
20+
}
21+
22+
return this.Ok(sessions);
23+
}
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Data.Entity;
2+
using System.Threading.Tasks;
3+
using System.Web.Http;
4+
using System.Linq;
5+
6+
namespace WebApi.Controller
7+
{
8+
public class TicketController : ApiController
9+
{
10+
[Route("api/tickets/{ticketId}")]
11+
[HttpGet]
12+
public async Task<IHttpActionResult> GetTicket(string ticketId)
13+
{
14+
using (var context = new ConferenceContext())
15+
{
16+
var ticket = await context.Tickets.FirstOrDefaultAsync(t => t.TicketId == ticketId);
17+
if (ticket == null)
18+
{
19+
return this.NotFound();
20+
}
21+
22+
return this.Ok(ticket);
23+
}
24+
}
25+
26+
[Route("api/tickets/{ticketId}", Name = "TicketRoute")]
27+
[HttpPut]
28+
public async Task<IHttpActionResult> SaveTicket(Ticket ticket)
29+
{
30+
using (var context = new ConferenceContext())
31+
{
32+
context.Entry(ticket).State = EntityState.Modified;
33+
await context.SaveChangesAsync();
34+
return this.Ok();
35+
}
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Entity;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace WebApi
8+
{
9+
public class ConferenceContext : DbContext
10+
{
11+
public ConferenceContext()
12+
: base("ConferenceDB")
13+
{ }
14+
15+
public DbSet<Ticket> Tickets { get; set; }
16+
17+
public DbSet<Session> Sessions { get; set; }
18+
19+
public DbSet<SessionRating> Ratings { get; set; }
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Data.Entity;
3+
using System.Data.Entity.Migrations;
4+
using System.Linq;
5+
6+
namespace WebApi.Migrations
7+
{
8+
internal sealed class Configuration : DbMigrationsConfiguration<WebApi.ConferenceContext>
9+
{
10+
public Configuration()
11+
{
12+
AutomaticMigrationsEnabled = true;
13+
ContextKey = "WebApi.ConferenceContext";
14+
}
15+
16+
protected override void Seed(WebApi.ConferenceContext context)
17+
{
18+
Ticket ticket;
19+
context.Tickets.AddOrUpdate(
20+
t => t.TicketId,
21+
ticket = new Ticket() { TicketId = "abc123", FirstName = "Max", LastName = "Muster", Email = "[email protected]" });
22+
23+
Session s1, s2, s3;
24+
context.Sessions.AddOrUpdate(
25+
s => s.SessionId,
26+
s1 = new Session() { SessionId = new Guid("{BAC9E4AE-2FEF-458F-9C4C-F5C4757F595B}"), Title = "AngularJS Basics" },
27+
s2 = new Session() { SessionId = new Guid("{A8DCCAFE-26CF-4E57-92CA-DA5E49546F71}"), Title = "Azure Deep Dive" },
28+
s3 = new Session() { SessionId = new Guid("{293A016E-1FB0-4513-851E-955C66822D59}"), Title = "Fun with Web API" });
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel.DataAnnotations;
5+
using System.Linq;
6+
using System.Web;
7+
8+
namespace WebApi
9+
{
10+
public class Session
11+
{
12+
[Key]
13+
[Required]
14+
[JsonProperty(PropertyName = "sessionId")]
15+
public Guid SessionId { get; set; }
16+
17+
[MaxLength(50)]
18+
[JsonProperty(PropertyName = "title")]
19+
public string Title { get; set; }
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel.DataAnnotations;
5+
using System.Linq;
6+
using System.Web;
7+
8+
namespace WebApi
9+
{
10+
public class SessionRating
11+
{
12+
public SessionRating()
13+
{
14+
this.RatingID = Guid.NewGuid();
15+
}
16+
17+
[Key]
18+
[Required]
19+
[JsonProperty(PropertyName = "ratingId")]
20+
public Guid RatingID { get; set; }
21+
22+
[Required]
23+
[JsonProperty(PropertyName = "ticket")]
24+
public Ticket Ticket { get; set; }
25+
26+
[Required]
27+
[JsonProperty(PropertyName = "session")]
28+
public Session Session { get; set; }
29+
30+
[JsonProperty(PropertyName = "rating")]
31+
public int Rating { get; set; }
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace WebApi
8+
{
9+
public class SessionRatingDto
10+
{
11+
[JsonProperty(PropertyName = "ticketId")]
12+
public string TicketId { get; set; }
13+
14+
[JsonProperty(PropertyName = "sessionId")]
15+
public Guid SessionId { get; set; }
16+
17+
[JsonProperty(PropertyName = "rating")]
18+
public int Rating { get; set; }
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Newtonsoft.Json;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace WebApi
5+
{
6+
public class Ticket
7+
{
8+
[Key]
9+
[Required]
10+
[MaxLength(50)]
11+
[JsonProperty(PropertyName = "ticketId")]
12+
public string TicketId { get; set; }
13+
14+
[MaxLength(50)]
15+
[JsonProperty(PropertyName = "firstName")]
16+
public string FirstName { get; set; }
17+
18+
[MaxLength(50)]
19+
[JsonProperty(PropertyName = "lastName")]
20+
public string LastName { get; set; }
21+
22+
[MaxLength(50)]
23+
[JsonProperty(PropertyName = "email")]
24+
public string Email { get; set; }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("WebApi")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("WebApi")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("bbce73fd-f44f-4b84-9b41-cd3b44844be5")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Revision and Build Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Owin;
2+
using Microsoft.Owin.Cors;
3+
using Owin;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net.Http.Headers;
7+
using System.Web.Http;
8+
using System.Web.Http.Dependencies;
9+
10+
[assembly: OwinStartup(typeof(WebApi.Startup))]
11+
12+
namespace WebApi
13+
{
14+
public class Startup
15+
{
16+
public void Configuration(IAppBuilder app)
17+
{
18+
app.UseCors(CorsOptions.AllowAll);
19+
20+
var config = new HttpConfiguration();
21+
config.MapHttpAttributeRoutes();
22+
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
23+
app.UseWebApi(config);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)