From 7d9ede9534d3e9ded65b9d6d34bff46c58d545d0 Mon Sep 17 00:00:00 2001
From: TMatome <46716771+TMatome@users.noreply.github.com>
Date: Tue, 22 Jan 2019 14:30:20 +0200
Subject: [PATCH 1/2] Created migration and updated connection string
---
.vscode/launch.json | 46 +++++++++++
.vscode/tasks.json | 15 ++++
data/createdatabase.sql | 76 +++++++++----------
data/createuser.sql | 12 +--
...0190122085109_InitialMigration.Designer.cs | 57 ++++++++++++++
.../20190122085109_InitialMigration.cs | 40 ++++++++++
.../TimesheetContextModelSnapshot.cs | 55 ++++++++++++++
.../MyTimesheet/MyTimesheet.csproj | 1 +
src/MyTimesheet/MyTimesheet/Startup.cs | 4 +-
9 files changed, 261 insertions(+), 45 deletions(-)
create mode 100644 .vscode/launch.json
create mode 100644 .vscode/tasks.json
create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.Designer.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..90342a4
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,46 @@
+{
+ // Use IntelliSense to find out which attributes exist for C# debugging
+ // Use hover for the description of the existing attributes
+ // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": ".NET Core Launch (web)",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "build",
+ // If you have changed target frameworks, make sure to update the program path.
+ "program": "${workspaceFolder}/src/MyTimesheet/MyTimesheet/bin/Debug/netcoreapp2.2/MyTimesheet.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}/src/MyTimesheet/MyTimesheet",
+ "stopAtEntry": false,
+ "internalConsoleOptions": "openOnSessionStart",
+ "launchBrowser": {
+ "enabled": true,
+ "args": "${auto-detect-url}",
+ "windows": {
+ "command": "cmd.exe",
+ "args": "/C start ${auto-detect-url}"
+ },
+ "osx": {
+ "command": "open"
+ },
+ "linux": {
+ "command": "xdg-open"
+ }
+ },
+ "env": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "sourceFileMap": {
+ "/Views": "${workspaceFolder}/Views"
+ }
+ },
+ {
+ "name": ".NET Core Attach",
+ "type": "coreclr",
+ "request": "attach",
+ "processId": "${command:pickProcess}"
+ }
+ ,]
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 0000000..0a18066
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,15 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "build",
+ "command": "dotnet",
+ "type": "process",
+ "args": [
+ "build",
+ "${workspaceFolder}/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj"
+ ],
+ "problemMatcher": "$msCompile"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/data/createdatabase.sql b/data/createdatabase.sql
index 41b5a17..5ea168e 100644
--- a/data/createdatabase.sql
+++ b/data/createdatabase.sql
@@ -1,115 +1,115 @@
USE [master]
GO
-/****** Object: Database [sql101.firstname.lastname] Script Date: 1/21/2019 9:11:50 PM ******/
-CREATE DATABASE [sql101.firstname.lastname]
+/****** Object: Database [sql101.tshenolo.matome] Script Date: 1/21/2019 9:11:50 PM ******/
+CREATE DATABASE [sql101.tshenolo.matome]
CONTAINMENT = NONE
ON PRIMARY
-( NAME = N'sql101.firstname.lastname', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.firstname.lastname.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
+( NAME = N'sql101.tshenolo.matome', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.tshenolo.matome.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
-( NAME = N'sql101.firstname.lastname_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.firstname.lastname_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
+( NAME = N'sql101.tshenolo.matome_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.tshenolo.matome_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
-ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130
+ALTER DATABASE [sql101.tshenolo.matome] SET COMPATIBILITY_LEVEL = 130
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
-EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable'
+EXEC [sql101.tshenolo.matome].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ANSI_NULL_DEFAULT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ANSI_NULLS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ANSI_PADDING OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ANSI_WARNINGS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ARITHABORT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET AUTO_CLOSE OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET AUTO_SHRINK OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON
+ALTER DATABASE [sql101.tshenolo.matome] SET AUTO_UPDATE_STATISTICS ON
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL
+ALTER DATABASE [sql101.tshenolo.matome] SET CURSOR_DEFAULT GLOBAL
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET CONCAT_NULL_YIELDS_NULL OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET NUMERIC_ROUNDABORT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET QUOTED_IDENTIFIER OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET RECURSIVE_TRIGGERS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER
+ALTER DATABASE [sql101.tshenolo.matome] SET DISABLE_BROKER
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET TRUSTWORTHY OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE
+ALTER DATABASE [sql101.tshenolo.matome] SET PARAMETERIZATION SIMPLE
GO
-ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET READ_COMMITTED_SNAPSHOT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET HONOR_BROKER_PRIORITY OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL
+ALTER DATABASE [sql101.tshenolo.matome] SET RECOVERY FULL
GO
-ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER
+ALTER DATABASE [sql101.tshenolo.matome] SET MULTI_USER
GO
-ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM
+ALTER DATABASE [sql101.tshenolo.matome] SET PAGE_VERIFY CHECKSUM
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET DB_CHAINING OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
+ALTER DATABASE [sql101.tshenolo.matome] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
-ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS
+ALTER DATABASE [sql101.tshenolo.matome] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED
+ALTER DATABASE [sql101.tshenolo.matome] SET DELAYED_DURABILITY = DISABLED
GO
-ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF
+ALTER DATABASE [sql101.tshenolo.matome] SET QUERY_STORE = OFF
GO
-USE [sql101.firstname.lastname]
+USE [sql101.tshenolo.matome]
GO
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
@@ -124,7 +124,7 @@ GO
ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
GO
-ALTER DATABASE [sql101.firstname.lastname] SET READ_WRITE
+ALTER DATABASE [sql101.tshenolo.matome] SET READ_WRITE
GO
diff --git a/data/createuser.sql b/data/createuser.sql
index bcf3038..b344a9d 100644
--- a/data/createuser.sql
+++ b/data/createuser.sql
@@ -1,18 +1,18 @@
USE [master]
GO
-CREATE LOGIN [firstnamelastname] WITH PASSWORD=N'rabbit123!@#' MUST_CHANGE, DEFAULT_DATABASE=[sql101.firstname.lastname], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
+CREATE LOGIN [tshenolomatome] WITH PASSWORD=N'rabbit123!@#' MUST_CHANGE, DEFAULT_DATABASE=[sql101.tshenolo.matome], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
GO
-use [sql101.firstname.lastname]
+use [sql101.tshenolo.matome]
GO
use [master]
GO
-USE [sql101.firstname.lastname]
+USE [sql101.tshenolo.matome]
GO
-CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname]
+CREATE USER [tshenolomatome] FOR LOGIN [tshenolomatome]
GO
-USE [sql101.firstname.lastname]
+USE [sql101.tshenolo.matome]
GO
-ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname]
+ALTER ROLE [db_owner] ADD MEMBER [tshenolomatome]
GO
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.Designer.cs
new file mode 100644
index 0000000..91e6a8d
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.Designer.cs
@@ -0,0 +1,57 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using MyTimesheet.Models;
+
+namespace MyTimesheet.Migrations
+{
+ [DbContext(typeof(TimesheetContext))]
+ [Migration("20190122085109_InitialMigration")]
+ partial class InitialMigration
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "2.2.1-servicing-10028")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Client");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Name");
+
+ b.Property("Project");
+
+ b.Property("Surname");
+
+ b.Property("TimeEnd");
+
+ b.Property("TimeStart");
+
+ b.HasKey("Id");
+
+ b.ToTable("Entries");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.cs
new file mode 100644
index 0000000..bd41006
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085109_InitialMigration.cs
@@ -0,0 +1,40 @@
+using System;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace MyTimesheet.Migrations
+{
+ public partial class InitialMigration : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Entries",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(nullable: true),
+ Surname = table.Column(nullable: true),
+ Client = table.Column(nullable: true),
+ Project = table.Column(nullable: true),
+ Date = table.Column(nullable: false),
+ TimeStart = table.Column(nullable: false),
+ TimeEnd = table.Column(nullable: false),
+ Duration = table.Column(nullable: false),
+ Description = table.Column(nullable: true),
+ Billable = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Entries", x => x.Id);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Entries");
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
new file mode 100644
index 0000000..6404921
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
@@ -0,0 +1,55 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using MyTimesheet.Models;
+
+namespace MyTimesheet.Migrations
+{
+ [DbContext(typeof(TimesheetContext))]
+ partial class TimesheetContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "2.2.1-servicing-10028")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Client");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Name");
+
+ b.Property("Project");
+
+ b.Property("Surname");
+
+ b.Property("TimeEnd");
+
+ b.Property("TimeStart");
+
+ b.HasKey("Id");
+
+ b.ToTable("Entries");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
index 54dfccf..2388bc5 100644
--- a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
+++ b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
@@ -6,6 +6,7 @@
+
diff --git a/src/MyTimesheet/MyTimesheet/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs
index e81072d..34e25be 100644
--- a/src/MyTimesheet/MyTimesheet/Startup.cs
+++ b/src/MyTimesheet/MyTimesheet/Startup.cs
@@ -35,7 +35,9 @@ public void ConfigureServices(IServiceCollection services)
c.SwaggerDoc("v1", new Info { Title = "My Timesheet API", Version = "v1" });
});
- var connection = @"Server=sql101labs1793591179000.westeurope.cloudapp.azure.com;Database=sql101.#NAME.SURNAME;User Id=myUsername;Password=myPassword;";
+ // var connection = @"Server=sql101labs1793591179000.westeurope.cloudapp.azure.com;Database=sql101.#NAME.SURNAME;User Id=myUsername;Password=myPassword;";
+ var connection = @"Server=sql101labs1793591179000.westeurope.cloudapp.azure.com;Database=sql101.tshenolo.matome;User Id=tshenolomatome;Password=%Vx1800%;";
+
services.AddDbContext
(options => options.UseSqlServer(connection));
}
From 24da1f173b40a0cde35e56d22b77aa6e282137e5 Mon Sep 17 00:00:00 2001
From: TMatome <46716771+TMatome@users.noreply.github.com>
Date: Sat, 26 Jan 2019 23:44:18 +0200
Subject: [PATCH 2/2] normalization and migration
---
src/MyTimesheet/MyTimesheet.sln | 4 +-
.../MyTimesheet/CacheSecrets.config | 4 +
.../Controllers/ClientController.cs | 82 ++++++++++++++++
.../Controllers/DeveloperController.cs | 82 ++++++++++++++++
.../Controllers/TimesheetController.cs | 22 ++++-
...6213732_normalizationMigration.Designer.cs | 95 +++++++++++++++++++
.../20190126213732_normalizationMigration.cs | 53 +++++++++++
.../TimesheetContextModelSnapshot.cs | 38 ++++++++
src/MyTimesheet/MyTimesheet/Models/Client.cs | 25 +++++
.../MyTimesheet/Models/Developer.cs | 21 ++++
.../MyTimesheet/Models/TimesheetContext.cs | 4 +
.../MyTimesheet/MyTimesheet.csproj | 2 +-
src/MyTimesheet/MyTimesheet/Startup.cs | 2 +
src/MyTimesheet/MyTimesheet/appsettings.json | 3 +-
src/MyTimesheet/cachedSecret.xml | 1 +
15 files changed, 434 insertions(+), 4 deletions(-)
create mode 100644 src/MyTimesheet/MyTimesheet/CacheSecrets.config
create mode 100644 src/MyTimesheet/MyTimesheet/Controllers/ClientController.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.Designer.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Models/Client.cs
create mode 100644 src/MyTimesheet/MyTimesheet/Models/Developer.cs
create mode 100644 src/MyTimesheet/cachedSecret.xml
diff --git a/src/MyTimesheet/MyTimesheet.sln b/src/MyTimesheet/MyTimesheet.sln
index 9c43c15..9773a27 100644
--- a/src/MyTimesheet/MyTimesheet.sln
+++ b/src/MyTimesheet/MyTimesheet.sln
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.271
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyTimesheet", "MyTimesheet\MyTimesheet.csproj", "{D8B4A42D-BD07-460B-B086-AE3724E2A5E5}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTimesheet", "MyTimesheet\MyTimesheet.csproj", "{D8B4A42D-BD07-460B-B086-AE3724E2A5E5}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C46D80E-D424-4366-B4CD-E28755F96C8B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/src/MyTimesheet/MyTimesheet/CacheSecrets.config b/src/MyTimesheet/MyTimesheet/CacheSecrets.config
new file mode 100644
index 0000000..6a4ed2c
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/CacheSecrets.config
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/MyTimesheet/MyTimesheet/Controllers/ClientController.cs b/src/MyTimesheet/MyTimesheet/Controllers/ClientController.cs
new file mode 100644
index 0000000..b78f508
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Controllers/ClientController.cs
@@ -0,0 +1,82 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using MyTimesheet.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class ClientController : ControllerBase
+ {
+ private readonly TimesheetContext _db;
+
+ public ClientController(TimesheetContext context)
+ {
+ _db = context;
+
+ }
+
+ // GET api/values
+ [HttpGet]
+ public async Task>> Get()
+ {
+ return await _db.ClientEntries.ToListAsync();
+ }
+
+ // GET api/values/5
+ [HttpGet("{id}")]
+ public async Task> Get(int id)
+ {
+ return await _db.ClientEntries.FindAsync(id);
+ }
+
+ // POST api/values
+ [HttpPost]
+ public async Task Post([FromBody] Client value)
+ {
+ await _db.ClientEntries.AddAsync(value);
+ await _db.SaveChangesAsync();
+
+ // var cacheConnection = _config.GetValue("CacheConnection").ToString();
+
+ //var lazyConnection = new Lazy(() =>
+ //{
+ //return ConnectionMultiplexer.Connect(cacheConnection);
+ // });
+ // IDatabase cache = lazyConnection.Value.GetDatabase();
+ // await cache.StringSetAsync($"{value.Name}-{value.Surname}",value.ToString());
+
+ //var cacheItem = await cache.StringGetAsync($"{value.Name}-{value.Surname}");
+
+
+ // lazyConnection.Value.Dispose();
+ // return cacheItem;
+
+ }
+
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public async Task Put(int id, [FromBody] Client value)
+ {
+ var entry = await _db.ClientEntries.FindAsync(id);
+ entry = value;
+ await _db.SaveChangesAsync();
+ }
+
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public async Task Delete(int id)
+ {
+ var entry = await _db.ClientEntries.FindAsync(id);
+ _db.ClientEntries.Remove(entry);
+ await _db.SaveChangesAsync();
+ }
+ }
+
+
+}
diff --git a/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs b/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs
new file mode 100644
index 0000000..3fb2e46
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs
@@ -0,0 +1,82 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using MyTimesheet.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class DeveloperController: ControllerBase
+ {
+ private readonly TimesheetContext _db;
+
+ public DeveloperController(TimesheetContext context)
+ {
+ _db = context;
+
+ }
+
+ // GET api/values
+ [HttpGet]
+ public async Task>> Get()
+ {
+ return await _db.DevEntries.ToListAsync();
+ }
+
+ // GET api/values/5
+ [HttpGet("{id}")]
+ public async Task> Get(int id)
+ {
+ return await _db.DevEntries.FindAsync(id);
+ }
+
+ // POST api/values
+ [HttpPost]
+ public async Task Post([FromBody] Developer value)
+ {
+ await _db.DevEntries.AddAsync(value);
+ await _db.SaveChangesAsync();
+
+ // var cacheConnection = _config.GetValue("CacheConnection").ToString();
+
+ //var lazyConnection = new Lazy(() =>
+ //{
+ //return ConnectionMultiplexer.Connect(cacheConnection);
+ // });
+ // IDatabase cache = lazyConnection.Value.GetDatabase();
+ // await cache.StringSetAsync($"{value.Name}-{value.Surname}",value.ToString());
+
+ //var cacheItem = await cache.StringGetAsync($"{value.Name}-{value.Surname}");
+
+
+ // lazyConnection.Value.Dispose();
+ // return cacheItem;
+
+ }
+
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public async Task Put(int id, [FromBody] Developer value)
+ {
+ var entry = await _db.DevEntries.FindAsync(id);
+ entry = value;
+ await _db.SaveChangesAsync();
+ }
+
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public async Task Delete(int id)
+ {
+ var entry = await _db.DevEntries.FindAsync(id);
+ _db.DevEntries.Remove(entry);
+ await _db.SaveChangesAsync();
+ }
+ }
+
+
+}
diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
index b2f5a7c..3982588 100644
--- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
+++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
using MyTimesheet.Models;
+using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,9 +15,11 @@ namespace MyTimesheet.Controllers
public class TimesheetController : ControllerBase
{
private readonly TimesheetContext _db;
- public TimesheetController(TimesheetContext context)
+ readonly IConfiguration _config;
+ public TimesheetController(TimesheetContext context,IConfiguration config)
{
_db = context;
+ _config = config;
}
// GET api/values
@@ -38,6 +42,22 @@ public async Task Post([FromBody] TimesheetEntry value)
{
await _db.Entries.AddAsync(value);
await _db.SaveChangesAsync();
+
+ // var cacheConnection = _config.GetValue("CacheConnection").ToString();
+
+ //var lazyConnection = new Lazy(() =>
+//{
+ //return ConnectionMultiplexer.Connect(cacheConnection);
+ // });
+ // IDatabase cache = lazyConnection.Value.GetDatabase();
+ // await cache.StringSetAsync($"{value.Name}-{value.Surname}",value.ToString());
+
+ //var cacheItem = await cache.StringGetAsync($"{value.Name}-{value.Surname}");
+
+
+ // lazyConnection.Value.Dispose();
+ // return cacheItem;
+
}
// PUT api/values/5
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.Designer.cs
new file mode 100644
index 0000000..b0e1fe9
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.Designer.cs
@@ -0,0 +1,95 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using MyTimesheet.Models;
+
+namespace MyTimesheet.Migrations
+{
+ [DbContext(typeof(TimesheetContext))]
+ [Migration("20190126213732_normalizationMigration")]
+ partial class normalizationMigration
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "2.2.1-servicing-10028")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("MyTimesheet.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Clients");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Project");
+
+ b.HasKey("Id");
+
+ b.ToTable("ClientEntries");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Developer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.Property("Surname");
+
+ b.HasKey("Id");
+
+ b.ToTable("DevEntries");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Client");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Name");
+
+ b.Property("Project");
+
+ b.Property("Surname");
+
+ b.Property("TimeEnd");
+
+ b.Property("TimeStart");
+
+ b.HasKey("Id");
+
+ b.ToTable("Entries");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.cs
new file mode 100644
index 0000000..c648737
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126213732_normalizationMigration.cs
@@ -0,0 +1,53 @@
+using System;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace MyTimesheet.Migrations
+{
+ public partial class normalizationMigration : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "ClientEntries",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Clients = table.Column(nullable: true),
+ Project = table.Column(nullable: true),
+ Date = table.Column(nullable: false),
+ Duration = table.Column(nullable: false),
+ Description = table.Column(nullable: true),
+ Billable = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_ClientEntries", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "DevEntries",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(nullable: true),
+ Surname = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_DevEntries", x => x.Id);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "ClientEntries");
+
+ migrationBuilder.DropTable(
+ name: "DevEntries");
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
index 6404921..5b9e49a 100644
--- a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
+++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
@@ -19,6 +19,44 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+ modelBuilder.Entity("MyTimesheet.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Clients");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Project");
+
+ b.HasKey("Id");
+
+ b.ToTable("ClientEntries");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Developer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.Property("Surname");
+
+ b.HasKey("Id");
+
+ b.ToTable("DevEntries");
+ });
+
modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
{
b.Property("Id")
diff --git a/src/MyTimesheet/MyTimesheet/Models/Client.cs b/src/MyTimesheet/MyTimesheet/Models/Client.cs
new file mode 100644
index 0000000..4111807
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Models/Client.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Models
+{
+ public class Client
+ {
+ /*
+ Id | Client | Project | Date | Duration | Description | Billable
+ ----| | --- | --- | --- | | ---
+ 1002 | Client X | Website | 2019-01-22 | 120 | I was rocking HTML5 | YES
+ 1805 | Client X | API | 2019-01-22 | 240 | Grafting on golang api | YES
+ */
+
+ public int Id { get; set; }
+ public string Clients { get; set; }
+ public string Project { get; set; }
+ public DateTime Date { get; set; }
+ public int Duration { get; set; }
+ public string Description { get; set; }
+ public bool Billable { get; set; }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Models/Developer.cs b/src/MyTimesheet/MyTimesheet/Models/Developer.cs
new file mode 100644
index 0000000..bd35cf5
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Models/Developer.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Models
+{
+ public class Developer
+ {
+ /*
+ Id | Name | Surname|
+ | -----| -------|
+ 201 | John | Doe |
+ 107 | John | Doe |
+ */
+
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Surname { get; set; }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
index 5bf7e22..62dc7ab 100644
--- a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
+++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
@@ -13,6 +13,10 @@ public TimesheetContext(DbContextOptions options)
{ }
public DbSet Entries { get; set; }
+ public DbSet ClientEntries { get; set; }
+ public DbSet DevEntries { get; set; }
+
+
}
}
diff --git a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
index 2388bc5..ac55499 100644
--- a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
+++ b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/src/MyTimesheet/MyTimesheet/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs
index 34e25be..9ce7f66 100644
--- a/src/MyTimesheet/MyTimesheet/Startup.cs
+++ b/src/MyTimesheet/MyTimesheet/Startup.cs
@@ -40,6 +40,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddDbContext
(options => options.UseSqlServer(connection));
+
+ services.AddSingleton(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
diff --git a/src/MyTimesheet/MyTimesheet/appsettings.json b/src/MyTimesheet/MyTimesheet/appsettings.json
index def9159..9dfd8a5 100644
--- a/src/MyTimesheet/MyTimesheet/appsettings.json
+++ b/src/MyTimesheet/MyTimesheet/appsettings.json
@@ -4,5 +4,6 @@
"Default": "Warning"
}
},
- "AllowedHosts": "*"
+ "AllowedHosts": "*",
+ "CacheConnection": "101.redis.cache.windows.net,abortConnect=false,ssl=true,password=85BYRVqUHV6aW7Jz8zIIxRnaYMgbBd2kwo4bpDiz4vw="
}
diff --git a/src/MyTimesheet/cachedSecret.xml b/src/MyTimesheet/cachedSecret.xml
new file mode 100644
index 0000000..8af98cb
--- /dev/null
+++ b/src/MyTimesheet/cachedSecret.xml
@@ -0,0 +1 @@
+