Skip to content

Commit

Permalink
Add Model and configuration for Data
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdrm committed Jul 25, 2016
1 parent 959f4cb commit 7411eb4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
15 changes: 15 additions & 0 deletions Model/DataContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;

namespace HabraQuest.Model
{
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options)
: base(options)
{
}


public DbSet<Player> Players { get; set; }
}
}
13 changes: 13 additions & 0 deletions Model/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace HabraQuest.Model
{
public class Player
{
public int Id { get; set; }
public Guid Token { get; set; }
public int TaskNumber { get; set; }
public string Name { get; set; }
public string Comment { get; set; }
}
}
25 changes: 20 additions & 5 deletions Startup.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using HabraQuest.Model;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;


namespace HabraQuest
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

builder.AddEnvironmentVariables();
Configuration = builder.Build();
}

public IConfigurationRoot Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
Expand Down
3 changes: 3 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-HabraQuest;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
Expand Down

0 comments on commit 7411eb4

Please sign in to comment.