diff --git a/data/createdatabase.sql b/data/createdatabase.sql index 41b5a17..778bdeb 100644 --- a/data/createdatabase.sql +++ b/data/createdatabase.sql @@ -2,114 +2,114 @@ USE [master] GO /****** Object: Database [sql101.firstname.lastname] Script Date: 1/21/2019 9:11:50 PM ******/ -CREATE DATABASE [sql101.firstname.lastname] +CREATE DATABASE [sql101.Nombuso.Sibiya] 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.Nombuso.Sibiya', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Nombuso.Sibiya.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.Nombuso.Sibiya_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Nombuso.Sibiya_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO -ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130 +ALTER DATABASE [sql101.Nombuso.Sibiya] SET COMPATIBILITY_LEVEL = 130 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin -EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable' +EXEC [sql101.Nombuso.Sibiya].[dbo].[sp_fulltext_database] @action = 'enable' end GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ANSI_NULL_DEFAULT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ANSI_NULLS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ANSI_PADDING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ANSI_WARNINGS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ARITHABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET AUTO_CLOSE OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET AUTO_SHRINK OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON +ALTER DATABASE [sql101.Nombuso.Sibiya] SET AUTO_UPDATE_STATISTICS ON GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET CURSOR_CLOSE_ON_COMMIT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL +ALTER DATABASE [sql101.Nombuso.Sibiya] SET CURSOR_DEFAULT GLOBAL GO -ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET CONCAT_NULL_YIELDS_NULL OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET NUMERIC_ROUNDABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET QUOTED_IDENTIFIER OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET RECURSIVE_TRIGGERS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER +ALTER DATABASE [sql101.Nombuso.Sibiya] SET DISABLE_BROKER GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET DATE_CORRELATION_OPTIMIZATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET TRUSTWORTHY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET ALLOW_SNAPSHOT_ISOLATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE +ALTER DATABASE [sql101.Nombuso.Sibiya] SET PARAMETERIZATION SIMPLE GO -ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET READ_COMMITTED_SNAPSHOT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET HONOR_BROKER_PRIORITY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL +ALTER DATABASE [sql101.Nombuso.Sibiya] SET RECOVERY FULL GO -ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER +ALTER DATABASE [sql101.Nombuso.Sibiya] SET MULTI_USER GO -ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM +ALTER DATABASE [sql101.Nombuso.Sibiya] SET PAGE_VERIFY CHECKSUM GO -ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET DB_CHAINING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) +ALTER DATABASE [sql101.Nombuso.Sibiya] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO -ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS +ALTER DATABASE [sql101.Nombuso.Sibiya] SET TARGET_RECOVERY_TIME = 60 SECONDS GO -ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED +ALTER DATABASE [sql101.Nombuso.Sibiya] SET DELAYED_DURABILITY = DISABLED GO -ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF +ALTER DATABASE [sql101.Nombuso.Sibiya] SET QUERY_STORE = OFF GO -USE [sql101.firstname.lastname] +USE [sql101.Nombuso.Sibiya] 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.Nombuso.Sibiya] SET READ_WRITE GO diff --git a/data/createuser.sql b/data/createuser.sql index bcf3038..d92cf41 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 [NombusoSibiya] WITH PASSWORD=N'rabbit123!@#' MUST_CHANGE, DEFAULT_DATABASE=[sql101.Nombuso.Sibiya], CHECK_EXPIRATION=ON, CHECK_POLICY=ON GO -use [sql101.firstname.lastname] +use [sql101.Nombuso.Sibiya] GO use [master] GO -USE [sql101.firstname.lastname] +USE [sql101.Nombuso.Sibiya] GO -CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname] +CREATE USER [NombusoSibiya] FOR LOGIN [NombusoSibiya] GO -USE [sql101.firstname.lastname] +USE [sql101.Nombuso.Sibiya] GO -ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname] +ALTER ROLE [db_owner] ADD MEMBER [NombusoSibiya] GO diff --git a/src/MyTimesheet/MyTimesheet/CacheSecrets.config b/src/MyTimesheet/MyTimesheet/CacheSecrets.config new file mode 100644 index 0000000..816505e --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/CacheSecrets.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs index b2f5a7c..b91d323 100644 --- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs +++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using MyTimesheet.Models; +using Newtonsoft.Json; +using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; @@ -13,31 +16,75 @@ 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 [HttpGet] public async Task>> Get() { + return await _db.Entries.ToListAsync(); } // GET api/values/5 [HttpGet("{id}")] - public async Task> Get(int id) + public async Task Get(int id) { - return await _db.Entries.FindAsync(id); + var cacheConnection = _config.GetValue("CacheConnection").ToString(); + + var lazyConnection = new Lazy(() => + { + + return ConnectionMultiplexer.Connect(cacheConnection); + }); + + IDatabase cache = lazyConnection.Value.GetDatabase(); + var cacheItem = await cache.StringGetAsync(id.ToString()); + + + return cacheItem; } // 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(); + + + + //var lazyConnection = new Lazy(() => + //{ + // string cacheConnection = ConfigurationManager.AppSettings["CacheConnection"].ToString(); + // return ConnectionMultiplexer.Connect(cacheConnection); + //}); + + //// Connection refers to a property that returns a ConnectionMultiplexer + //// as shown in the previous example. + //IDatabase cache = lazyConnection.Value.GetDatabase(); + + var data = await _db.Entries.Include(v => v.Employee).Include(c => c.Project).Include(c => c.Project.Client).FirstOrDefaultAsync(x => x.Employee.Id == value.Employee.Id); + var lazyConnection = new Lazy(() => + { + + return ConnectionMultiplexer.Connect(cacheConnection); + }); + + IDatabase cache = lazyConnection.Value.GetDatabase(); + + await cache.StringSetAsync(data.Id.ToString(), JsonConvert.SerializeObject(data)); + + var cacheItem = await cache.StringGetAsync(data.Id.ToString()); + + lazyConnection.Value.Dispose(); + return cacheItem.ToString(); ; } // PUT api/values/5 diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.Designer.cs new file mode 100644 index 0000000..e0e6a68 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.Designer.cs @@ -0,0 +1,120 @@ +// +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("20190126191933_TimeSheet")] + partial class TimeSheet + { + 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.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClientId"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Duration"); + + b.Property("EmployeeId"); + + b.Property("ProjectId"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("ProjectId"); + + b.ToTable("Entries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.HasOne("MyTimesheet.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.HasOne("MyTimesheet.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId"); + + b.HasOne("MyTimesheet.Models.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.cs new file mode 100644 index 0000000..7e59dad --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126191933_TimeSheet.cs @@ -0,0 +1,121 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class TimeSheet : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + 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_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Projects", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true), + ClientId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Projects", x => x.Id); + table.ForeignKey( + name: "FK_Projects_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Entries", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + 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), + EmployeeId = table.Column(nullable: true), + ProjectId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Entries", x => x.Id); + table.ForeignKey( + name: "FK_Entries_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Entries_Projects_ProjectId", + column: x => x.ProjectId, + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Entries_EmployeeId", + table: "Entries", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_Entries_ProjectId", + table: "Entries", + column: "ProjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Projects_ClientId", + table: "Projects", + column: "ClientId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Entries"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Projects"); + + migrationBuilder.DropTable( + name: "Clients"); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.Designer.cs new file mode 100644 index 0000000..b9ca783 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.Designer.cs @@ -0,0 +1,120 @@ +// +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("20190126192501_Normalisation")] + partial class Normalisation + { + 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.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClientId"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Duration"); + + b.Property("EmployeeId"); + + b.Property("ProjectId"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("ProjectId"); + + b.ToTable("Entries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.HasOne("MyTimesheet.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.HasOne("MyTimesheet.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId"); + + b.HasOne("MyTimesheet.Models.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.cs new file mode 100644 index 0000000..fd0be85 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126192501_Normalisation.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class Normalisation : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs new file mode 100644 index 0000000..2f95044 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs @@ -0,0 +1,118 @@ +// +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.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClientId"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Duration"); + + b.Property("EmployeeId"); + + b.Property("ProjectId"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("ProjectId"); + + b.ToTable("Entries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.HasOne("MyTimesheet.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.HasOne("MyTimesheet.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId"); + + b.HasOne("MyTimesheet.Models.Project", "Project") + .WithMany() + .HasForeignKey("ProjectId"); + }); +#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..3fb9790 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Client.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Client + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/Employee.cs b/src/MyTimesheet/MyTimesheet/Models/Employee.cs new file mode 100644 index 0000000..61f873e --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Employee.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Employee + { + public int Id { get; set; } + public string Name { get; set; } + public string Surname { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/Project.cs b/src/MyTimesheet/MyTimesheet/Models/Project.cs new file mode 100644 index 0000000..4220a8a --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Project.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Project + { + public int Id { get; set; } + public string Name { get; set; } + public Client Client { get; set; } + + + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs index 5bf7e22..6e08caf 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs @@ -13,6 +13,9 @@ public TimesheetContext(DbContextOptions options) { } public DbSet Entries { get; set; } + public DbSet Employees { get; set; } + public DbSet Clients { get; set; } + public DbSet Projects { get; set; } } } diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs index 8c65667..74f5314 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs @@ -15,15 +15,13 @@ 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 Employee Employee { get; set; } + public Project Project { get; set; } } } diff --git a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj index 54dfccf..0cf8abb 100644 --- a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj +++ b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj @@ -13,4 +13,8 @@ + + + + diff --git a/src/MyTimesheet/MyTimesheet/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs index e81072d..15dd0be 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.Nombuso.Sibiya;User Id=NombusoSibiya;Password=retro4@;"; 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=" }