From e3e3eddac54bf8ee10662b53fe20998ec68f5362 Mon Sep 17 00:00:00 2001 From: LindanyRetroRabbit Date: Tue, 22 Jan 2019 14:27:00 +0200 Subject: [PATCH 1/3] Successfully updated the database login and inserted data --- data/createdatabase.sql | 76 +++++++++---------- data/createuser.sql | 12 +-- .../20190122085823_InitialCreate.Designer.cs | 57 ++++++++++++++ .../20190122085823_InitialCreate.cs | 40 ++++++++++ .../TimesheetContextModelSnapshot.cs | 55 ++++++++++++++ src/MyTimesheet/MyTimesheet/Startup.cs | 2 +- 6 files changed, 197 insertions(+), 45 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs diff --git a/data/createdatabase.sql b/data/createdatabase.sql index 41b5a17..74e847d 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.Lindani.Mabaso] Script Date: 1/21/2019 9:11:50 PM ******/ +CREATE DATABASE [sql101.Lindani.Mabaso] 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.Lindani.Mabaso', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Lindani.Mabaso.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.Lindani.Mabaso_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Lindani.Mabaso_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO -ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130 +ALTER DATABASE [sql101.Lindani.Mabaso] SET COMPATIBILITY_LEVEL = 130 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin -EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable' +EXEC [sql101.Lindani.Mabaso].[dbo].[sp_fulltext_database] @action = 'enable' end GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ANSI_NULL_DEFAULT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ANSI_NULLS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ANSI_PADDING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ANSI_WARNINGS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ARITHABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET AUTO_CLOSE OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET AUTO_SHRINK OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON +ALTER DATABASE [sql101.Lindani.Mabaso] SET AUTO_UPDATE_STATISTICS ON GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET CURSOR_CLOSE_ON_COMMIT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL +ALTER DATABASE [sql101.Lindani.Mabaso] SET CURSOR_DEFAULT GLOBAL GO -ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET CONCAT_NULL_YIELDS_NULL OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET NUMERIC_ROUNDABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET QUOTED_IDENTIFIER OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET RECURSIVE_TRIGGERS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER +ALTER DATABASE [sql101.Lindani.Mabaso] SET DISABLE_BROKER GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET DATE_CORRELATION_OPTIMIZATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET TRUSTWORTHY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET ALLOW_SNAPSHOT_ISOLATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE +ALTER DATABASE [sql101.Lindani.Mabaso] SET PARAMETERIZATION SIMPLE GO -ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET READ_COMMITTED_SNAPSHOT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET HONOR_BROKER_PRIORITY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL +ALTER DATABASE [sql101.Lindani.Mabaso] SET RECOVERY FULL GO -ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER +ALTER DATABASE [sql101.Lindani.Mabaso] SET MULTI_USER GO -ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM +ALTER DATABASE [sql101.Lindani.Mabaso] SET PAGE_VERIFY CHECKSUM GO -ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET DB_CHAINING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) +ALTER DATABASE [sql101.Lindani.Mabaso] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO -ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS +ALTER DATABASE [sql101.Lindani.Mabaso] SET TARGET_RECOVERY_TIME = 60 SECONDS GO -ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED +ALTER DATABASE [sql101.Lindani.Mabaso] SET DELAYED_DURABILITY = DISABLED GO -ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF +ALTER DATABASE [sql101.Lindani.Mabaso] SET QUERY_STORE = OFF GO -USE [sql101.firstname.lastname] +USE [sql101.Lindani.Mabaso] 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.Lindani.Mabaso] SET READ_WRITE GO diff --git a/data/createuser.sql b/data/createuser.sql index bcf3038..1021d17 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 [LindaniMabaso] WITH PASSWORD=N'Lindany#016' MUST_CHANGE, DEFAULT_DATABASE=[sql101.Lindani.Mabaso], CHECK_EXPIRATION=ON, CHECK_POLICY=ON GO -use [sql101.firstname.lastname] +use [sql101.Lindani.Mabaso] GO use [master] GO -USE [sql101.firstname.lastname] +USE [sql101.Lindani.Mabaso] GO -CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname] +CREATE USER [LindaniMabaso] FOR LOGIN [LindaniMabaso] GO -USE [sql101.firstname.lastname] +USE [sql101.Lindani.Mabaso] GO -ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname] +ALTER ROLE [db_owner] ADD MEMBER [LindaniMabaso] GO diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.Designer.cs new file mode 100644 index 0000000..7e95c9a --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.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("20190122085823_InitialCreate")] + partial class InitialCreate + { + 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/20190122085823_InitialCreate.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.cs new file mode 100644 index 0000000..f49fcb6 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122085823_InitialCreate.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class InitialCreate : 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/Startup.cs b/src/MyTimesheet/MyTimesheet/Startup.cs index e81072d..9a081f4 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.Lindani.Mabaso;User Id=LindaniMabaso;Password=Lindany@retro;"; services.AddDbContext (options => options.UseSqlServer(connection)); } From b8dd40c9e20734af458134ad30e3cf61bf7cbfeb Mon Sep 17 00:00:00 2001 From: LindanyRetroRabbit Date: Sat, 26 Jan 2019 18:24:58 +0200 Subject: [PATCH 2/3] Migration Pushed --- .../MyTimesheet/CacheSecrets.config | 4 ++ .../Controllers/TimesheetController.cs | 51 ++++++++++++++++- .../20190126154530_Init.Designer.cs | 57 +++++++++++++++++++ .../Migrations/20190126154530_Init.cs | 17 ++++++ .../20190126155430_Homework.Designer.cs | 57 +++++++++++++++++++ .../Migrations/20190126155430_Homework.cs | 17 ++++++ ...190126160412_HomeworkMigration.Designer.cs | 57 +++++++++++++++++++ .../20190126160412_HomeworkMigration.cs | 17 ++++++ src/MyTimesheet/MyTimesheet/Models/Client.cs | 15 +++++ .../MyTimesheet/Models/Developer.cs | 17 ++++++ src/MyTimesheet/MyTimesheet/Models/Project.cs | 20 +++++++ .../MyTimesheet/Models/ProjectDate.cs | 21 +++++++ .../MyTimesheet/Models/TimesheetEntry.cs | 51 +++++++++++++---- .../MyTimesheet/MyTimesheet.csproj | 1 + src/MyTimesheet/MyTimesheet/Startup.cs | 1 + src/MyTimesheet/MyTimesheet/appsettings.json | 3 +- 16 files changed, 392 insertions(+), 14 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/CacheSecrets.config create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/Client.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/Developer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/Project.cs create mode 100644 src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs 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..b962965 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,17 @@ namespace MyTimesheet.Controllers public class TimesheetController : ControllerBase { private readonly TimesheetContext _db; - public TimesheetController(TimesheetContext context) + + public IConfiguration IConfiguration { get; } + public object MyRedisConnectorHelper { get; private set; } + public object RedisConnectorHelper { get; private set; } + + readonly IConfiguration _config; + public TimesheetController(TimesheetContext context, IConfiguration _config) { _db = context; + IConfiguration = _config; + } // GET api/values @@ -34,12 +44,42 @@ 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 lazyConnecction = new Lazy(() => + { + return ConnectionMultiplexer.Connect(cacheConnection); + }); + + IDatabase cache = lazyConnecction.Value.GetDatabase(); + //var cacheItem = await cache.StringGetAsync($"{value.Name}--{value.Surname}"); + await cache.StringSetAsync($"{value.Name}-{value.Surname}",value.ToString()); + var cacheItem = await cache.StringGetAsync($"{value.Name}--{value.Surname}"); + lazyConnecction.Value.Dispose(); + + var cach = RedisConnectorHelper.Connection.GetDatabase(); + cach.StringSet(cacheItem); + + // var cacheItem = cache.Execute("KEYS","LIST").ToString();' + ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhhost"); + redis.StringSet(cacheItem); + //IDatabase db = redis. + return cacheItem; } + public void SaveRedisBigData() + { + + var cache = MyRedisConnectorHelper.RedisConnection.GetDatabase(); + cache.StringSet($"MySampleData:{i}", value); + + } + + } // PUT api/values/5 [HttpPut("{id}")] public async Task Put(int id, [FromBody] TimesheetEntry value) @@ -47,7 +87,12 @@ public async Task Put(int id, [FromBody] TimesheetEntry value) var entry = await _db.Entries.FindAsync(id); entry = value; await _db.SaveChangesAsync(); - } + ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhhost"); + //IDatabase db = redis. + + ConnectionMultiplexer cach = RedisConnectorHelper.Connection.GetDatabase(); + cach.StringSet(cacheItem); + } // DELETE api/values/5 [HttpDelete("{id}")] diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.Designer.cs new file mode 100644 index 0000000..c2b07e7 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.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("20190126154530_Init")] + partial class Init + { + 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/20190126154530_Init.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.cs new file mode 100644 index 0000000..d55f478 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126154530_Init.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class Init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.Designer.cs new file mode 100644 index 0000000..ef0acdc --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.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("20190126155430_Homework")] + partial class Homework + { + 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/20190126155430_Homework.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.cs new file mode 100644 index 0000000..a83e59a --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126155430_Homework.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class Homework : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.Designer.cs new file mode 100644 index 0000000..447947d --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.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("20190126160412_HomeworkMigration")] + partial class HomeworkMigration + { + 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/20190126160412_HomeworkMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.cs new file mode 100644 index 0000000..d933785 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126160412_HomeworkMigration.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class HomeworkMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/Client.cs b/src/MyTimesheet/MyTimesheet/Models/Client.cs new file mode 100644 index 0000000..a8e3bf8 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Client.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Client + { + [Key] + public int Client_ID { get; set; } + public string Name { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/Developer.cs b/src/MyTimesheet/MyTimesheet/Models/Developer.cs new file mode 100644 index 0000000..88db2a5 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Developer.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Developer + { + [Key] + public int Dev_ID { get; set; } + public string Name { get; set; } + public string Surname { get; set; } + public string Description { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/Project.cs b/src/MyTimesheet/MyTimesheet/Models/Project.cs new file mode 100644 index 0000000..e6bb28f --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Project.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class Project + { + [Key] + public int Project_ID { get; set; } + + [ForeignKey("Cient")] + public int Client_ID { get; set; } + + public bool Billable { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs b/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs new file mode 100644 index 0000000..7f6e83d --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class ProjectDate + { + [ForeignKey("Project")] + public int Project_ID { get; set; } + + [ForeignKey("Client")] + public int Client_ID { get; set; } + + public DateTime Date { get; set; } + public DateTime TimeStart { get; set; } + public DateTime TimeEnd { get; set; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs index 8c65667..204b75b 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs @@ -14,16 +14,47 @@ public class TimesheetEntry John | Doe | Client X | API | 2019-01-22 | 13:00 | 17:00 | 240 | Grafting on golang api | YES */ + + /* + | Name | Surname | Dev_ID | Description + | --- | ---------| -------- | ---------- Developer + | John | Doe | 1 | I was rocking HTML5 + | John | Doe | 2 | Grafting on golang api + + | Client_ID | Name | + | -------- | ------ | + | John | Client X | Client + | John | Client X | + + + | Project | Billable | Client_ID | + | -------- | ----------- | -------- | + | Client X | YES | 001 | Project + | Client X | YES | 002 | + + + | Client_ID | Project_ID | Date | Time Started | Time ended | Duration | + | --- | --- | --------- | ------------ | ---------- | -------- | ProjectDate + | 001 | Website | 2019-01-22 | 09:00 | 11:00 | 120 | + | 002 | API | 2019-01-22 | 13:00 | 17:00 | 240 | + + Lindani R Mabaso + */ + + + 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 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; } + } } + \ No newline at end of file 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 9a081f4..186df23 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.Lindani.Mabaso;User Id=LindaniMabaso;Password=Lindany@retro;"; 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 3689a2a538ac2d1fb31bd31175c928deeacdcb48 Mon Sep 17 00:00:00 2001 From: LindanyRetroRabbit Date: Sat, 26 Jan 2019 19:37:12 +0200 Subject: [PATCH 3/3] Four tables updates --- .../Controllers/TimesheetController.cs | 28 +--- ...2317_HomeworkMigration_Updated.Designer.cs | 57 ++++++++ ...0190126172317_HomeworkMigration_Updated.cs | 97 ++++++++++++++ ...0190126173431_Updated_Homework.Designer.cs | 123 ++++++++++++++++++ .../20190126173431_Updated_Homework.cs | 112 ++++++++++++++++ .../TimesheetContextModelSnapshot.cs | 76 ++++++++++- .../MyTimesheet/Models/ProjectDate.cs | 4 +- .../MyTimesheet/Models/TimesheetContext.cs | 4 + .../MyTimesheet/Models/TimesheetEntry.cs | 28 ++-- 9 files changed, 487 insertions(+), 42 deletions(-) create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.Designer.cs create mode 100644 src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.cs diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs index b962965..1f5c676 100644 --- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs +++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs @@ -17,8 +17,6 @@ public class TimesheetController : ControllerBase private readonly TimesheetContext _db; public IConfiguration IConfiguration { get; } - public object MyRedisConnectorHelper { get; private set; } - public object RedisConnectorHelper { get; private set; } readonly IConfiguration _config; public TimesheetController(TimesheetContext context, IConfiguration _config) @@ -61,25 +59,12 @@ public async Task Post([FromBody] TimesheetEntry value) var cacheItem = await cache.StringGetAsync($"{value.Name}--{value.Surname}"); lazyConnecction.Value.Dispose(); - var cach = RedisConnectorHelper.Connection.GetDatabase(); - cach.StringSet(cacheItem); - - // var cacheItem = cache.Execute("KEYS","LIST").ToString();' - ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhhost"); - redis.StringSet(cacheItem); - //IDatabase db = redis. + //cache.StringSet("Message","Hello! The cache is working"); +// + // var cacheItem = cache.Execute("KEYS","LIST").ToString(); return cacheItem; } - public void SaveRedisBigData() - { - - var cache = MyRedisConnectorHelper.RedisConnection.GetDatabase(); - cache.StringSet($"MySampleData:{i}", value); - - } - - } // PUT api/values/5 [HttpPut("{id}")] public async Task Put(int id, [FromBody] TimesheetEntry value) @@ -87,12 +72,7 @@ public async Task Put(int id, [FromBody] TimesheetEntry value) var entry = await _db.Entries.FindAsync(id); entry = value; await _db.SaveChangesAsync(); - ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhhost"); - //IDatabase db = redis. - - ConnectionMultiplexer cach = RedisConnectorHelper.Connection.GetDatabase(); - cach.StringSet(cacheItem); - } + } // DELETE api/values/5 [HttpDelete("{id}")] diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.Designer.cs new file mode 100644 index 0000000..af33aae --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.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("20190126172317_HomeworkMigration_Updated")] + partial class HomeworkMigration_Updated + { + 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("Timesheet_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client_ID"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Dev_ID"); + + b.Property("Name"); + + b.Property("Project_ID"); + + b.Property("Surname"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Timesheet_ID"); + + b.ToTable("TimesheetEntry"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.cs new file mode 100644 index 0000000..18825cd --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126172317_HomeworkMigration_Updated.cs @@ -0,0 +1,97 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class HomeworkMigration_Updated : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Entries", + table: "Entries"); + + migrationBuilder.DropColumn( + name: "Client", + table: "Entries"); + + migrationBuilder.DropColumn( + name: "Project", + table: "Entries"); + + migrationBuilder.RenameTable( + name: "Entries", + newName: "TimesheetEntry"); + + migrationBuilder.RenameColumn( + name: "Duration", + table: "TimesheetEntry", + newName: "Project_ID"); + + migrationBuilder.RenameColumn( + name: "Id", + table: "TimesheetEntry", + newName: "Timesheet_ID"); + + migrationBuilder.AddColumn( + name: "Client_ID", + table: "TimesheetEntry", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Dev_ID", + table: "TimesheetEntry", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddPrimaryKey( + name: "PK_TimesheetEntry", + table: "TimesheetEntry", + column: "Timesheet_ID"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_TimesheetEntry", + table: "TimesheetEntry"); + + migrationBuilder.DropColumn( + name: "Client_ID", + table: "TimesheetEntry"); + + migrationBuilder.DropColumn( + name: "Dev_ID", + table: "TimesheetEntry"); + + migrationBuilder.RenameTable( + name: "TimesheetEntry", + newName: "Entries"); + + migrationBuilder.RenameColumn( + name: "Project_ID", + table: "Entries", + newName: "Duration"); + + migrationBuilder.RenameColumn( + name: "Timesheet_ID", + table: "Entries", + newName: "Id"); + + migrationBuilder.AddColumn( + name: "Client", + table: "Entries", + nullable: true); + + migrationBuilder.AddColumn( + name: "Project", + table: "Entries", + nullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_Entries", + table: "Entries", + column: "Id"); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.Designer.cs new file mode 100644 index 0000000..421f523 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.Designer.cs @@ -0,0 +1,123 @@ +// +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("20190126173431_Updated_Homework")] + partial class Updated_Homework + { + 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("Client_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.HasKey("Client_ID"); + + b.ToTable("Client"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Developer", b => + { + b.Property("Dev_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Dev_ID"); + + b.ToTable("Developer"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Project_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client_ID"); + + b.HasKey("Project_ID"); + + b.ToTable("Project"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDate", b => + { + b.Property("ProjectDate_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Client_ID"); + + b.Property("Date"); + + b.Property("Project_ID"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("ProjectDate_ID"); + + b.ToTable("ProjectDate"); + }); + + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => + { + b.Property("Timesheet_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client_ID"); + + b.Property("Date"); + + b.Property("Description"); + + b.Property("Dev_ID"); + + b.Property("Name"); + + b.Property("Project_ID"); + + b.Property("Surname"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Timesheet_ID"); + + b.ToTable("Entries"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.cs new file mode 100644 index 0000000..7878802 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126173431_Updated_Homework.cs @@ -0,0 +1,112 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class Updated_Homework : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_TimesheetEntry", + table: "TimesheetEntry"); + + migrationBuilder.RenameTable( + name: "TimesheetEntry", + newName: "Entries"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Entries", + table: "Entries", + column: "Timesheet_ID"); + + migrationBuilder.CreateTable( + name: "Client", + columns: table => new + { + Client_ID = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Client", x => x.Client_ID); + }); + + migrationBuilder.CreateTable( + name: "Developer", + columns: table => new + { + Dev_ID = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true), + Surname = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Developer", x => x.Dev_ID); + }); + + migrationBuilder.CreateTable( + name: "Project", + columns: table => new + { + Project_ID = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Client_ID = table.Column(nullable: false), + Billable = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Project", x => x.Project_ID); + }); + + migrationBuilder.CreateTable( + name: "ProjectDate", + columns: table => new + { + ProjectDate_ID = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Project_ID = table.Column(nullable: false), + Client_ID = table.Column(nullable: false), + Date = table.Column(nullable: false), + TimeStart = table.Column(nullable: false), + TimeEnd = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProjectDate", x => x.ProjectDate_ID); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Client"); + + migrationBuilder.DropTable( + name: "Developer"); + + migrationBuilder.DropTable( + name: "Project"); + + migrationBuilder.DropTable( + name: "ProjectDate"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Entries", + table: "Entries"); + + migrationBuilder.RenameTable( + name: "Entries", + newName: "TimesheetEntry"); + + migrationBuilder.AddPrimaryKey( + name: "PK_TimesheetEntry", + table: "TimesheetEntry", + column: "Timesheet_ID"); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs index 6404921..6cd23db 100644 --- a/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs +++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs @@ -19,25 +19,91 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + modelBuilder.Entity("MyTimesheet.Models.Client", b => + { + b.Property("Client_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.HasKey("Client_ID"); + + b.ToTable("Client"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Developer", b => + { + b.Property("Dev_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Dev_ID"); + + b.ToTable("Developer"); + }); + + modelBuilder.Entity("MyTimesheet.Models.Project", b => + { + b.Property("Project_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client_ID"); + + b.HasKey("Project_ID"); + + b.ToTable("Project"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDate", b => + { + b.Property("ProjectDate_ID") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Client_ID"); + + b.Property("Date"); + + b.Property("Project_ID"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("ProjectDate_ID"); + + b.ToTable("ProjectDate"); + }); + modelBuilder.Entity("MyTimesheet.Models.TimesheetEntry", b => { - b.Property("Id") + b.Property("Timesheet_ID") .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); b.Property("Billable"); - b.Property("Client"); + b.Property("Client_ID"); b.Property("Date"); b.Property("Description"); - b.Property("Duration"); + b.Property("Dev_ID"); b.Property("Name"); - b.Property("Project"); + b.Property("Project_ID"); b.Property("Surname"); @@ -45,7 +111,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("TimeStart"); - b.HasKey("Id"); + b.HasKey("Timesheet_ID"); b.ToTable("Entries"); }); diff --git a/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs b/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs index 7f6e83d..a3b7355 100644 --- a/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs +++ b/src/MyTimesheet/MyTimesheet/Models/ProjectDate.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; @@ -8,9 +9,10 @@ namespace MyTimesheet.Models { public class ProjectDate { + [Key] + public int ProjectDate_ID { get; set; } [ForeignKey("Project")] public int Project_ID { get; set; } - [ForeignKey("Client")] public int Client_ID { get; set; } diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetContext.cs index 5bf7e22..936a919 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 Project { get; set; } + public DbSet Client { get; set; } + public DbSet ProjectDate { get; set; } + public DbSet Developer { get; set; } } } diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs index 204b75b..6fd6269 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; @@ -42,19 +44,21 @@ Lindani R Mabaso */ + [Key] + public int Timesheet_ID { get; set; } + [ForeignKey("Cient")] + public int Client_ID { get; set; } + public bool Billable { get; set; } + [ForeignKey("Project")] + public int Project_ID { get; set; } + public DateTime Date { get; set; } + public DateTime TimeStart { get; set; } + public DateTime TimeEnd { get; set; } + public int Dev_ID { get; set; } + public string Name { get; set; } + public string Surname { get; set; } + public string Description { get; set; } - 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; } - } } \ No newline at end of file