diff --git a/data/createdatabase.sql b/data/createdatabase.sql
index 41b5a17..3e06351 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.Joseph.LeGrand] Script Date: 1/21/2019 9:11:50 PM ******/
+CREATE DATABASE [sql101.Joseph.LeGrand]
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.Joseph.LeGrand', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Joseph.LeGrand.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.Joseph.LeGrand_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Joseph.LeGrand_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
-ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130
+ALTER DATABASE [sql101.Joseph.LeGrand] SET COMPATIBILITY_LEVEL = 130
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
-EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable'
+EXEC [sql101.Joseph.LeGrand].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ANSI_NULL_DEFAULT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ANSI_NULLS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ANSI_PADDING OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ANSI_WARNINGS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ARITHABORT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET AUTO_CLOSE OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET AUTO_SHRINK OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON
+ALTER DATABASE [sql101.Joseph.LeGrand] SET AUTO_UPDATE_STATISTICS ON
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL
+ALTER DATABASE [sql101.Joseph.LeGrand] SET CURSOR_DEFAULT GLOBAL
GO
-ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET CONCAT_NULL_YIELDS_NULL OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET NUMERIC_ROUNDABORT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET QUOTED_IDENTIFIER OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET RECURSIVE_TRIGGERS OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER
+ALTER DATABASE [sql101.Joseph.LeGrand] SET DISABLE_BROKER
GO
-ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET TRUSTWORTHY OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE
+ALTER DATABASE [sql101.Joseph.LeGrand] SET PARAMETERIZATION SIMPLE
GO
-ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET READ_COMMITTED_SNAPSHOT OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET HONOR_BROKER_PRIORITY OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL
+ALTER DATABASE [sql101.Joseph.LeGrand] SET RECOVERY FULL
GO
-ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER
+ALTER DATABASE [sql101.Joseph.LeGrand] SET MULTI_USER
GO
-ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM
+ALTER DATABASE [sql101.Joseph.LeGrand] SET PAGE_VERIFY CHECKSUM
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET DB_CHAINING OFF
GO
-ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
+ALTER DATABASE [sql101.Joseph.LeGrand] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
-ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS
+ALTER DATABASE [sql101.Joseph.LeGrand] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
-ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED
+ALTER DATABASE [sql101.Joseph.LeGrand] SET DELAYED_DURABILITY = DISABLED
GO
-ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF
+ALTER DATABASE [sql101.Joseph.LeGrand] SET QUERY_STORE = OFF
GO
-USE [sql101.firstname.lastname]
+USE [sql101.Joseph.LeGrand]
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.Joseph.LeGrand] SET READ_WRITE
GO
diff --git a/data/createuser.sql b/data/createuser.sql
index bcf3038..d2e448e 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 [JosephLeGrand] WITH PASSWORD=N'rabbit123!@#' MUST_CHANGE, DEFAULT_DATABASE=[sql101.Joseph.LeGrand], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
GO
-use [sql101.firstname.lastname]
+use [sql101.Joseph.LeGrand]
GO
use [master]
GO
-USE [sql101.firstname.lastname]
+USE [sql101.Joseph.LeGrand]
GO
-CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname]
+CREATE USER [JosephLeGrand] FOR LOGIN [JosephLeGrand]
GO
-USE [sql101.firstname.lastname]
+USE [sql101.Joseph.LeGrand]
GO
-ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname]
+ALTER ROLE [db_owner] ADD MEMBER [JosephLeGrand]
GO
diff --git a/src/MyTimesheet/MyTimesheet/CacheSecrets.config b/src/MyTimesheet/MyTimesheet/CacheSecrets.config
new file mode 100644
index 0000000..d7cc356
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/CacheSecrets.config
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
index b2f5a7c..ea3d4d4 100644
--- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
+++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs
@@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Microsoft.Extensions.Configuration;
+using StackExchange.Redis;
namespace MyTimesheet.Controllers
{
@@ -13,9 +15,11 @@ namespace MyTimesheet.Controllers
public class TimesheetController : ControllerBase
{
private readonly TimesheetContext _db;
- public TimesheetController(TimesheetContext context)
+ private IConfiguration _config;
+ public TimesheetController(TimesheetContext context, IConfiguration configuration)
{
_db = context;
+ _config = configuration;
}
// GET api/values
@@ -29,15 +33,51 @@ public async Task>> Get()
[HttpGet("{id}")]
public async Task> Get(int id)
{
+ var cacheConnection = _config.GetValue("CacheConnection").ToString();//That is the connection string
+ var lazyConnection = new Lazy(() => //connecting to our Redis
+ {
+ //Connecting to Redis
+ return ConnectionMultiplexer.Connect(cacheConnection);
+ });
+
+ IDatabase cache = lazyConnection.Value.GetDatabase();//This is the connection to the Redis database
+
+ string key = Convert.ToString(id);
+ if (!cache.KeyExists(key))
+ {
+ return await _db.Entries.FindAsync(id);
+ }
+ else await cache.StringGetAsync(key);
return await _db.Entries.FindAsync(id);
}
// POST api/values
[HttpPost]
- public async Task Post([FromBody] TimesheetEntry value)
+ public async Task Post([FromBody] TimesheetEntry value)
{
await _db.Entries.AddAsync(value);
await _db.SaveChangesAsync();
+
+ var cacheConnection = _config.GetValue("CacheConnection").ToString();//That is the connection string
+ var lazyConnection = new Lazy(() => //connecting to our Redis
+ {
+ //Connecting to Redis
+ return ConnectionMultiplexer.Connect(cacheConnection);
+ });
+
+ IDatabase cache = lazyConnection.Value.GetDatabase();//This is the connection to the Redis database
+
+ //Adding to cache using this key which is the ID and the values
+ string key = Convert.ToString(value.Id);
+ await cache.StringSetAsync(key,value.ToString());
+ await cache.KeyPersistAsync(key); //Creating peristence on the key, in order for it to always be saved on cache
+
+ //List of people in our cache, remember cache lies in memory
+ var cacheItem = cache.Execute("KEYS", "*").ToString();
+
+ lazyConnection.Value.Dispose();
+
+ return cacheItem;
}
// PUT api/values/5
@@ -46,6 +86,20 @@ public async Task Put(int id, [FromBody] TimesheetEntry value)
{
var entry = await _db.Entries.FindAsync(id);
entry = value;
+
+ var cacheConnection = _config.GetValue("CacheConnection").ToString();//That is the connection string
+ var lazyConnection = new Lazy(() => //connecting to our Redis
+ {
+ //Connecting to Redis
+ return ConnectionMultiplexer.Connect(cacheConnection);
+ });
+
+ IDatabase cache = lazyConnection.Value.GetDatabase();//This is the connection to the Redis database
+
+ //Adding to cache using this key which is the ID and the values
+ string key = Convert.ToString(id);
+ await cache.StringSetAsync(key, value.ToString());
+ await cache.KeyPersistAsync(key); //Creating peristence on the key, in order for it to always be saved on cache
await _db.SaveChangesAsync();
}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122084839_CreatMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122084839_CreatMigration.Designer.cs
new file mode 100644
index 0000000..680b74e
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122084839_CreatMigration.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("20190122084839_CreatMigration")]
+ partial class CreatMigration
+ {
+ 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/20190122084839_CreatMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122084839_CreatMigration.cs
new file mode 100644
index 0000000..613221c
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122084839_CreatMigration.cs
@@ -0,0 +1,40 @@
+using System;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace MyTimesheet.Migrations
+{
+ public partial class CreatMigration : 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/20190126101201_NormalizationMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126101201_NormalizationMigration.Designer.cs
new file mode 100644
index 0000000..d0c5ea5
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126101201_NormalizationMigration.Designer.cs
@@ -0,0 +1,101 @@
+//
+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("20190126101201_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("Name");
+
+ b.Property("projectId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("projectId");
+
+ b.ToTable("clients");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Project", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Name");
+
+ b.Property("TimeEnd");
+
+ b.Property("TimeStart");
+
+ b.HasKey("Id");
+
+ b.ToTable("projects");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.Property("Surname");
+
+ b.Property("clientId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("clientId");
+
+ b.ToTable("Entries");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Client", b =>
+ {
+ b.HasOne("MyTimesheet.Models.Project", "project")
+ .WithMany()
+ .HasForeignKey("projectId");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.HasOne("MyTimesheet.Models.Client", "client")
+ .WithMany()
+ .HasForeignKey("clientId");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126101201_NormalizationMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126101201_NormalizationMigration.cs
new file mode 100644
index 0000000..c01e8f0
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126101201_NormalizationMigration.cs
@@ -0,0 +1,172 @@
+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.DropColumn(
+ name: "Billable",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "Client",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "Date",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "Description",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "Duration",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "Project",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "TimeEnd",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "TimeStart",
+ table: "Entries");
+
+ migrationBuilder.AddColumn(
+ name: "clientId",
+ table: "Entries",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "projects",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = 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_projects", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "clients",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(nullable: true),
+ projectId = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_clients", x => x.Id);
+ table.ForeignKey(
+ name: "FK_clients_projects_projectId",
+ column: x => x.projectId,
+ principalTable: "projects",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Entries_clientId",
+ table: "Entries",
+ column: "clientId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_clients_projectId",
+ table: "clients",
+ column: "projectId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Entries_clients_clientId",
+ table: "Entries",
+ column: "clientId",
+ principalTable: "clients",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Entries_clients_clientId",
+ table: "Entries");
+
+ migrationBuilder.DropTable(
+ name: "clients");
+
+ migrationBuilder.DropTable(
+ name: "projects");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Entries_clientId",
+ table: "Entries");
+
+ migrationBuilder.DropColumn(
+ name: "clientId",
+ table: "Entries");
+
+ migrationBuilder.AddColumn(
+ name: "Billable",
+ table: "Entries",
+ nullable: false,
+ defaultValue: false);
+
+ migrationBuilder.AddColumn(
+ name: "Client",
+ table: "Entries",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "Date",
+ table: "Entries",
+ nullable: false,
+ defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+
+ migrationBuilder.AddColumn(
+ name: "Description",
+ table: "Entries",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "Duration",
+ table: "Entries",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn(
+ name: "Project",
+ table: "Entries",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "TimeEnd",
+ table: "Entries",
+ nullable: false,
+ defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+
+ migrationBuilder.AddColumn(
+ name: "TimeStart",
+ table: "Entries",
+ nullable: false,
+ defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
new file mode 100644
index 0000000..88e98fa
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs
@@ -0,0 +1,99 @@
+//
+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.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.Property("projectId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("projectId");
+
+ b.ToTable("clients");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Project", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Billable");
+
+ b.Property("Date");
+
+ b.Property("Description");
+
+ b.Property("Duration");
+
+ b.Property("Name");
+
+ b.Property("TimeEnd");
+
+ b.Property("TimeStart");
+
+ b.HasKey("Id");
+
+ b.ToTable("projects");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.Property("Surname");
+
+ b.Property("clientId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("clientId");
+
+ b.ToTable("Entries");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.Client", b =>
+ {
+ b.HasOne("MyTimesheet.Models.Project", "project")
+ .WithMany()
+ .HasForeignKey("projectId");
+ });
+
+ modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b =>
+ {
+ b.HasOne("MyTimesheet.Models.Client", "client")
+ .WithMany()
+ .HasForeignKey("clientId");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Models/Client.cs b/src/MyTimesheet/MyTimesheet/Models/Client.cs
new file mode 100644
index 0000000..64e4b29
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Models/Client.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Models
+{
+ public class Client
+ {
+ //Nedbank
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public Project project { get; set; }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Models/Project.cs b/src/MyTimesheet/MyTimesheet/Models/Project.cs
new file mode 100644
index 0000000..b2f1482
--- /dev/null
+++ b/src/MyTimesheet/MyTimesheet/Models/Project.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MyTimesheet.Models
+{
+ public class Project
+ {
+ //Future Life | Suppliments for a healthy body
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public DateTime Date { get; set; }
+ public DateTime TimeStart { get; set; }
+ public DateTime TimeEnd { get; set; }
+ public int Duration { get; set; }
+ public string Description { get; set; }
+ public bool Billable { get; set; }
+ }
+}
diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
index 5bf7e22..917a210 100644
--- a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
+++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs
@@ -13,6 +13,7 @@ public TimesheetContext(DbContextOptions options)
{ }
public DbSet Entries { get; set; }
-
+ public DbSet projects { get; set; }
+ public DbSet clients { get; set; }
}
}
diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs
index 8c65667..7f0fe7d 100644
--- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs
+++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs
@@ -17,13 +17,7 @@ public class TimesheetEntry
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
- public string Client { get; set; }
- public string Project { get; set; }
- public DateTime Date { get; set; }
- public DateTime TimeStart { get; set; }
- public DateTime TimeEnd { get; set; }
- public int Duration { get; set; }
- public string Description { get; set; }
- public bool Billable { get; set; }
+ public Client client { get; set; }
+
}
}
diff --git a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
index 54dfccf..9c8113c 100644
--- a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
+++ b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp2.2
@@ -11,6 +11,7 @@
+
diff --git a/src/MyTimesheet/MyTimesheet/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs
index e81072d..4e097a1 100644
--- a/src/MyTimesheet/MyTimesheet/Startup.cs
+++ b/src/MyTimesheet/MyTimesheet/Startup.cs
@@ -35,9 +35,10 @@ 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.Joseph.LeGrand;User Id=JosephLeGrand;Password=Godisgood001_;";
services.AddDbContext
(options => options.UseSqlServer(connection));
+ services.AddSingleton(Configuration); // Using injection, whenever we need this we can add it to api controller
}
// 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="
}