From b5bc2a6154b92b321ea53d5dc7c3a72521248e52 Mon Sep 17 00:00:00 2001 From: lisaQ04 Date: Tue, 22 Jan 2019 14:27:04 +0200 Subject: [PATCH 1/3] Adding data to database --- data/createdatabase.sql | 76 +++++++++---------- data/createuser.sql | 12 +-- ...0190122085729_initialMigration.Designer.cs | 57 ++++++++++++++ .../20190122085729_initialMigration.cs | 40 ++++++++++ .../TimesheetContextModelSnapshot.cs | 55 ++++++++++++++ .../MyTimesheet/MyTimesheet.csproj | 1 + src/MyTimesheet/MyTimesheet/Startup.cs | 2 +- src/MyTimesheet/MyTimesheet/web.config | 16 ++++ 8 files changed, 214 insertions(+), 45 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085729_initialMigration.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085729_initialMigration.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs create mode 100644 src/MyTimesheet/MyTimesheet/web.config diff --git a/data/createdatabase.sql b/data/createdatabase.sql index 41b5a17..e070497 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.Lisa.Quluba] Script Date: 1/21/2019 9:11:50 PM ******/ +CREATE DATABASE [sql101.Lisa.Quluba] 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.Lisa.Quluba', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Lisa.Quluba.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.Lisa.Quluba_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Lisa.Quluba_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO -ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130 +ALTER DATABASE [sql101.Lisa.Quluba] SET COMPATIBILITY_LEVEL = 130 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin -EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable' +EXEC [sql101.Lisa.Quluba].[dbo].[sp_fulltext_database] @action = 'enable' end GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ANSI_NULL_DEFAULT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ANSI_NULLS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ANSI_PADDING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ANSI_WARNINGS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ARITHABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET AUTO_CLOSE OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET AUTO_SHRINK OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON +ALTER DATABASE [sql101.Lisa.Quluba] SET AUTO_UPDATE_STATISTICS ON GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET CURSOR_CLOSE_ON_COMMIT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL +ALTER DATABASE [sql101.Lisa.Quluba] SET CURSOR_DEFAULT GLOBAL GO -ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET CONCAT_NULL_YIELDS_NULL OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET NUMERIC_ROUNDABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET QUOTED_IDENTIFIER OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET RECURSIVE_TRIGGERS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER +ALTER DATABASE [sql101.Lisa.Quluba] SET DISABLE_BROKER GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET DATE_CORRELATION_OPTIMIZATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET TRUSTWORTHY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET ALLOW_SNAPSHOT_ISOLATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE +ALTER DATABASE [sql101.Lisa.Quluba] SET PARAMETERIZATION SIMPLE GO -ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET READ_COMMITTED_SNAPSHOT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET HONOR_BROKER_PRIORITY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL +ALTER DATABASE [sql101.Lisa.Quluba] SET RECOVERY FULL GO -ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER +ALTER DATABASE [sql101.Lisa.Quluba] SET MULTI_USER GO -ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM +ALTER DATABASE [sql101.Lisa.Quluba] SET PAGE_VERIFY CHECKSUM GO -ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET DB_CHAINING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) +ALTER DATABASE [sql101.Lisa.Quluba] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO -ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS +ALTER DATABASE [sql101.Lisa.Quluba] SET TARGET_RECOVERY_TIME = 60 SECONDS GO -ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED +ALTER DATABASE [sql101.Lisa.Quluba] SET DELAYED_DURABILITY = DISABLED GO -ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF +ALTER DATABASE [sql101.Lisa.Quluba] SET QUERY_STORE = OFF GO -USE [sql101.firstname.lastname] +USE [sql101.Lisa.Quluba] 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.Lisa.Quluba] SET READ_WRITE GO diff --git a/data/createuser.sql b/data/createuser.sql index bcf3038..5417f30 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 [LisaQuluba] WITH PASSWORD=N'LisaQ11@sql' MUST_CHANGE, DEFAULT_DATABASE=[sql101.Lisa.Quluba], CHECK_EXPIRATION=ON, CHECK_POLICY=ON GO -use [sql101.firstname.lastname] +use [sql101.Lisa.Quluba] GO use [master] GO -USE [sql101.firstname.lastname] +USE [sql101.Lisa.Quluba] GO -CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname] +CREATE USER [LisaQuluba] FOR LOGIN [LisaQuluba] GO -USE [sql101.firstname.lastname] +USE [sql101.Lisa.Quluba] GO -ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname] +ALTER ROLE [db_owner] ADD MEMBER [LisaQuluba] GO diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122085729_initialMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085729_initialMigration.Designer.cs new file mode 100644 index 0000000..fc99034 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085729_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("20190122085729_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/20190122085729_initialMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085729_initialMigration.cs new file mode 100644 index 0000000..93f8eb8 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085729_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..293cacb 100644 --- a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj +++ b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj @@ -9,6 +9,7 @@ + diff --git a/src/MyTimesheet/MyTimesheet/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs index e81072d..87a050b 100644 --- a/src/MyTimesheet/MyTimesheet/Startup.cs +++ b/src/MyTimesheet/MyTimesheet/Startup.cs @@ -35,7 +35,7 @@ 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.lisa.Quluba;User Id=LisaQuluba;Password=lisaQ11@sql;"; services.AddDbContext (options => options.UseSqlServer(connection)); } diff --git a/src/MyTimesheet/MyTimesheet/web.config b/src/MyTimesheet/MyTimesheet/web.config new file mode 100644 index 0000000..2ff1546 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/web.config @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file From 42b66e74ef703e7e657ef9a6821299302a2471fc Mon Sep 17 00:00:00 2001 From: lisaQ04 Date: Wed, 23 Jan 2019 16:28:09 +0200 Subject: [PATCH 2/3] Update Post Uses Redis Cache --- .../MyTimesheet/CacheSecrets.config | 5 +++++ .../Controllers/TimesheetController.cs | 19 +++++++++++++++++-- src/MyTimesheet/MyTimesheet/Startup.cs | 1 + src/MyTimesheet/MyTimesheet/appsettings.json | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/CacheSecrets.config diff --git a/src/MyTimesheet/MyTimesheet/CacheSecrets.config b/src/MyTimesheet/MyTimesheet/CacheSecrets.config new file mode 100644 index 0000000..fd33619 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/CacheSecrets.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs index b2f5a7c..8d17afb 100644 --- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs +++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs @@ -1,11 +1,14 @@ 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; using System.Threading.Tasks; + namespace MyTimesheet.Controllers { [Route("api/[controller]")] @@ -13,9 +16,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 @@ -34,10 +39,20 @@ public async Task> Get(int 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(); + 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/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs index 87a050b..d563150 100644 --- a/src/MyTimesheet/MyTimesheet/Startup.cs +++ b/src/MyTimesheet/MyTimesheet/Startup.cs @@ -38,6 +38,7 @@ public void ConfigureServices(IServiceCollection services) var connection = @"Server=sql101labs1793591179000.westeurope.cloudapp.azure.com;Database=sql101.lisa.Quluba;User Id=LisaQuluba;Password=lisaQ11@sql;"; 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=" } From d6ac924f3c754fb21dd4356c81f06f829c7f5beb Mon Sep 17 00:00:00 2001 From: lisaQ04 Date: Sat, 26 Jan 2019 19:32:57 +0200 Subject: [PATCH 3/3] normalizing data structure --- .../Controllers/TimesheetController.cs | 104 +++++++++--------- .../20190126171552_Normalized.Designer.cs | 78 +++++++++++++ .../Migrations/20190126171552_Normalized.cs | 91 +++++++++++++++ .../TimesheetContextModelSnapshot.cs | 39 +++++-- .../MyTimesheet/Models/Developer.cs | 16 +++ src/MyTimesheet/MyTimesheet/Models/Project.cs | 19 ++++ .../MyTimesheet/Models/TimesheetContext.cs | 3 +- .../MyTimesheet/Models/TimesheetEntry.cs | 13 +-- 8 files changed, 290 insertions(+), 73 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/Developer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/Project.cs diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs index 8d17afb..4cd9bf2 100644 --- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs +++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs @@ -15,62 +15,62 @@ namespace MyTimesheet.Controllers [ApiController] public class TimesheetController : ControllerBase { - private readonly TimesheetContext _db; - readonly IConfiguration _config; - public TimesheetController(TimesheetContext context, IConfiguration config) - { - _db = context; - _config = config; - } + // private readonly TimesheetContext _db; + // 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 + // [HttpGet] + // public async Task>> Get() + // { + // return await _db.Entries.ToListAsync(); + // } - // GET api/values/5 - [HttpGet("{id}")] - public async Task> Get(int id) - { - return await _db.Entries.FindAsync(id); - } + // // GET api/values/5 + // [HttpGet("{id}")] + // public async Task> Get(int id) + // { + // return await _db.Entries.FindAsync(id); + // } - // POST api/values - [HttpPost] - 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; - } + // // POST api/values + // [HttpPost] + // 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 - [HttpPut("{id}")] - public async Task Put(int id, [FromBody] TimesheetEntry value) - { - var entry = await _db.Entries.FindAsync(id); - entry = value; - await _db.SaveChangesAsync(); - } + // // PUT api/values/5 + // [HttpPut("{id}")] + // public async Task Put(int id, [FromBody] TimesheetEntry value) + // { + // var entry = await _db.Entries.FindAsync(id); + // entry = value; + // await _db.SaveChangesAsync(); + // } - // DELETE api/values/5 - [HttpDelete("{id}")] - public async Task Delete(int id) - { - var entry = await _db.Entries.FindAsync(id); - _db.Entries.Remove(entry); - await _db.SaveChangesAsync(); - } + // // DELETE api/values/5 + // [HttpDelete("{id}")] + // public async Task Delete(int id) + // { + // var entry = await _db.Entries.FindAsync(id); + // _db.Entries.Remove(entry); + // await _db.SaveChangesAsync(); + // } } } diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.Designer.cs new file mode 100644 index 0000000..53deee9 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.Designer.cs @@ -0,0 +1,78 @@ +// +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("20190126171552_Normalized")] + partial class Normalized + { + 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.Developer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Client"); + + b.Property("Name"); + + b.Property("Surname"); + + b.Property("projectId"); + + b.HasKey("Id"); + + b.HasIndex("projectId"); + + b.ToTable("Developer"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Billable"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Duration"); + + b.Property("Project_1"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.ToTable("Project"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Developer", b => + { + b.HasOne("MyTimesheet.Models.Project", "project") + .WithMany() + .HasForeignKey("projectId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.cs new file mode 100644 index 0000000..e2212fe --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126171552_Normalized.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class Normalized : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Entries"); + + migrationBuilder.CreateTable( + name: "Project", + columns: table => new + { + Id = table.Column(nullable: false), + Project_1 = 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_Project", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Developer", + 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), + projectId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Developer", x => x.Id); + table.ForeignKey( + name: "FK_Developer_Project_projectId", + column: x => x.projectId, + principalTable: "Project", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Developer_projectId", + table: "Developer", + column: "projectId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Developer"); + + migrationBuilder.DropTable( + name: "Project"); + + migrationBuilder.CreateTable( + name: "Entries", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Billable = table.Column(nullable: false), + Client = table.Column(nullable: true), + Date = table.Column(nullable: false), + Description = table.Column(nullable: true), + Duration = table.Column(nullable: false), + Name = table.Column(nullable: true), + Project = table.Column(nullable: true), + Surname = table.Column(nullable: true), + TimeEnd = table.Column(nullable: false), + TimeStart = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Entries", x => x.Id); + }); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs index 6404921..7c0d664 100644 --- a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs +++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs @@ -19,27 +19,41 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + modelBuilder.Entity("MyTimesheet.Models.Developer", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("Billable"); - b.Property("Client"); + b.Property("Name"); + + b.Property("Surname"); + + b.Property("projectId"); + + b.HasKey("Id"); + + b.HasIndex("projectId"); + + b.ToTable("Developer"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Billable"); + b.Property("Date"); b.Property("Description"); b.Property("Duration"); - b.Property("Name"); - - b.Property("Project"); - - b.Property("Surname"); + b.Property("Project_1"); b.Property("TimeEnd"); @@ -47,7 +61,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("Entries"); + b.ToTable("Project"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Developer", b => + { + b.HasOne("MyTimesheet.Models.Project", "project") + .WithMany() + .HasForeignKey("projectId"); }); #pragma warning restore 612, 618 } diff --git a/src/MyTimesheet/MyTimesheet/Models/Developer.cs b/src/MyTimesheet/MyTimesheet/Models/Developer.cs new file mode 100644 index 0000000..3d19f41 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Developer.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Developer + { + public int Id { get; set; } + public string Name { get; set; } + public string Surname { get; set; } + public string Client { 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..fc9e9dd --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Project.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Project + { + public string Id { get; set; } + public string Project_1 { 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..253a959 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs @@ -12,7 +12,8 @@ public TimesheetContext(DbContextOptions options) : base(options) { } - public DbSet Entries { get; set; } + public DbSet Developer { get; set; } + public DbSet Project { get; set; } } } diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs index 8c65667..98eca08 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs @@ -14,16 +14,7 @@ public class TimesheetEntry John | Doe | Client X | API | 2019-01-22 | 13:00 | 17:00 | 240 | Grafting on golang api | YES */ - 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; } + + } }