diff --git a/data/createdatabase.sql b/data/createdatabase.sql index 41b5a17..59ae4bb 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.Gift.Langa] 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.Gift.Langa', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Gift.Langa.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.Gift.Langa_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\sql101.Gift.Langa_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO -ALTER DATABASE [sql101.firstname.lastname] SET COMPATIBILITY_LEVEL = 130 +ALTER DATABASE [sql101.Gift.Langa] SET COMPATIBILITY_LEVEL = 130 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin -EXEC [sql101.firstname.lastname].[dbo].[sp_fulltext_database] @action = 'enable' +EXEC [sql101.Gift.Langa].[dbo].[sp_fulltext_database] @action = 'enable' end GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULL_DEFAULT OFF +ALTER DATABASE [sql101.Gift.Langa] SET ANSI_NULL_DEFAULT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_NULLS OFF +ALTER DATABASE [sql101.Gift.Langa] SET ANSI_NULLS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_PADDING OFF +ALTER DATABASE [sql101.Gift.Langa] SET ANSI_PADDING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ANSI_WARNINGS OFF +ALTER DATABASE [sql101.Gift.Langa] SET ANSI_WARNINGS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ARITHABORT OFF +ALTER DATABASE [sql101.Gift.Langa] SET ARITHABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_CLOSE OFF +ALTER DATABASE [sql101.Gift.Langa] SET AUTO_CLOSE OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_SHRINK OFF +ALTER DATABASE [sql101.Gift.Langa] SET AUTO_SHRINK OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS ON +ALTER DATABASE [sql101.Gift.Langa] SET AUTO_UPDATE_STATISTICS ON GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_CLOSE_ON_COMMIT OFF +ALTER DATABASE [sql101.Gift.Langa] SET CURSOR_CLOSE_ON_COMMIT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET CURSOR_DEFAULT GLOBAL +ALTER DATABASE [sql101.Gift.Langa] SET CURSOR_DEFAULT GLOBAL GO -ALTER DATABASE [sql101.firstname.lastname] SET CONCAT_NULL_YIELDS_NULL OFF +ALTER DATABASE [sql101.Gift.Langa] SET CONCAT_NULL_YIELDS_NULL OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET NUMERIC_ROUNDABORT OFF +ALTER DATABASE [sql101.Gift.Langa] SET NUMERIC_ROUNDABORT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET QUOTED_IDENTIFIER OFF +ALTER DATABASE [sql101.Gift.Langa] SET QUOTED_IDENTIFIER OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECURSIVE_TRIGGERS OFF +ALTER DATABASE [sql101.Gift.Langa] SET RECURSIVE_TRIGGERS OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DISABLE_BROKER +ALTER DATABASE [sql101.Gift.Langa] SET DISABLE_BROKER GO -ALTER DATABASE [sql101.firstname.lastname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF +ALTER DATABASE [sql101.Gift.Langa] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET DATE_CORRELATION_OPTIMIZATION OFF +ALTER DATABASE [sql101.Gift.Langa] SET DATE_CORRELATION_OPTIMIZATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET TRUSTWORTHY OFF +ALTER DATABASE [sql101.Gift.Langa] SET TRUSTWORTHY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET ALLOW_SNAPSHOT_ISOLATION OFF +ALTER DATABASE [sql101.Gift.Langa] SET ALLOW_SNAPSHOT_ISOLATION OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET PARAMETERIZATION SIMPLE +ALTER DATABASE [sql101.Gift.Langa] SET PARAMETERIZATION SIMPLE GO -ALTER DATABASE [sql101.firstname.lastname] SET READ_COMMITTED_SNAPSHOT OFF +ALTER DATABASE [sql101.Gift.Langa] SET READ_COMMITTED_SNAPSHOT OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET HONOR_BROKER_PRIORITY OFF +ALTER DATABASE [sql101.Gift.Langa] SET HONOR_BROKER_PRIORITY OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET RECOVERY FULL +ALTER DATABASE [sql101.Gift.Langa] SET RECOVERY FULL GO -ALTER DATABASE [sql101.firstname.lastname] SET MULTI_USER +ALTER DATABASE [sql101.Gift.Langa] SET MULTI_USER GO -ALTER DATABASE [sql101.firstname.lastname] SET PAGE_VERIFY CHECKSUM +ALTER DATABASE [sql101.Gift.Langa] SET PAGE_VERIFY CHECKSUM GO -ALTER DATABASE [sql101.firstname.lastname] SET DB_CHAINING OFF +ALTER DATABASE [sql101.Gift.Langa] SET DB_CHAINING OFF GO -ALTER DATABASE [sql101.firstname.lastname] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) +ALTER DATABASE [sql101.Gift.Langa] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO -ALTER DATABASE [sql101.firstname.lastname] SET TARGET_RECOVERY_TIME = 60 SECONDS +ALTER DATABASE [sql101.Gift.Langa] SET TARGET_RECOVERY_TIME = 60 SECONDS GO -ALTER DATABASE [sql101.firstname.lastname] SET DELAYED_DURABILITY = DISABLED +ALTER DATABASE [sql101.Gift.Langa] SET DELAYED_DURABILITY = DISABLED GO -ALTER DATABASE [sql101.firstname.lastname] SET QUERY_STORE = OFF +ALTER DATABASE [sql101.Gift.Langa] SET QUERY_STORE = OFF GO -USE [sql101.firstname.lastname] +USE [sql101.Gift.Langa] 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.Gift.Langa] SET READ_WRITE GO diff --git a/data/createuser.sql b/data/createuser.sql index bcf3038..abcda94 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 [GiftLanga] WITH PASSWORD=N'G4tDB__Xcs' MUST_CHANGE, DEFAULT_DATABASE=[sql101.Gift.Langa], CHECK_EXPIRATION=ON, CHECK_POLICY=ON GO -use [sql101.firstname.lastname] +use [sql101.Gift.Langa] GO use [master] GO -USE [sql101.firstname.lastname] +USE [sql101.Gift.Langa] GO -CREATE USER [firstnamelastname] FOR LOGIN [firstnamelastname] +CREATE USER [GiftLanga] FOR LOGIN [GiftLanga] GO -USE [sql101.firstname.lastname] +USE [sql101.Gift.Langa] GO -ALTER ROLE [db_owner] ADD MEMBER [firstnamelastname] +ALTER ROLE [db_owner] ADD MEMBER [GiftLanga] GO diff --git a/src/MyTimesheet/MyTimesheet/CachedSecrets.config b/src/MyTimesheet/MyTimesheet/CachedSecrets.config new file mode 100644 index 0000000..6a93e35 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/CachedSecrets.config @@ -0,0 +1,5 @@ + + + + + diff --git a/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs b/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs new file mode 100644 index 0000000..26054f2 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Controllers/DeveloperController.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MyTimesheet.Models; +using StackExchange.Redis; +using Newtonsoft.Json; + +namespace MyTimesheet.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class DeveloperController : ControllerBase + { + private readonly TimesheetContext _db; + private readonly IConfiguration _config; + private Lazy lazy; + string cacheConnection; + public DeveloperController(TimesheetContext context, IConfiguration config) + { + _db = context; + _config = config; + cacheConnection = _config.GetValue("CacheConnection").ToString(); + lazy = new Lazy(() => + { + return ConnectionMultiplexer.Connect(cacheConnection); + }); + } + // GET api/values + [HttpGet] + public async Task>> Get() + { + + try + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.ExecuteAsync("KEYS", "*"); + return JsonConvert.DeserializeObject>(result.ToString()); + } catch (Exception e) + { + return await _db.DeveloperEntries.ToListAsync(); + } + } + + // GET api/values/5 + [HttpGet("{id}")] + public async Task> Get(int id) + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.StringGetAsync($"{id}"); + + + if (!result.HasValue) + { + var value = await _db.DeveloperEntries.FindAsync(id); + await cache.StringSetAsync($"{id}", JsonConvert.SerializeObject(value)); + return value; + } else + { + return JsonConvert.DeserializeObject(result); + } + + } + + // POST api/values + [HttpPost] + public async Task Post([FromBody] Developer value) + { + + await _db.DeveloperEntries.AddAsync(value); + await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // PUT api/values/5 + [HttpPut("{id}")] + public async Task Put(int id, [FromBody] Developer value) + { + var entry = await _db.DeveloperEntries.FindAsync(id); + entry = value; + await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var entry = await _db.DeveloperEntries.FindAsync(id); + _db.DeveloperEntries.Remove(entry); + await _db.SaveChangesAsync(); + + } + } + +} \ No newline at end of file diff --git a/src/MyTimesheet/MyTimesheet/Controllers/ProjectDateTimeController.cs b/src/MyTimesheet/MyTimesheet/Controllers/ProjectDateTimeController.cs new file mode 100644 index 0000000..270a7a6 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Controllers/ProjectDateTimeController.cs @@ -0,0 +1,109 @@ +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; +using System.Threading.Tasks; + +namespace MyTimesheet.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ProjectDateTimeController : ControllerBase + { + private readonly TimesheetContext _db; + private readonly IConfiguration _config; + private Lazy lazy; + string cacheConnection; + + public ProjectDateTimeController(TimesheetContext context, IConfiguration config) + { + _db = context; + _db = context; + _config = config; + cacheConnection = _config.GetValue("CacheConnection").ToString(); + lazy = new Lazy(() => + { + return ConnectionMultiplexer.Connect(cacheConnection); + }); + } + + // GET api/values + [HttpGet] + public async Task>> Get() + { + try + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.ExecuteAsync("KEYS", "*"); + return JsonConvert.DeserializeObject>(result.ToString()); + } + catch (Exception e) + { + return await _db.ProjectDateTimeEntries.ToListAsync(); + } + } + + // GET api/values/5 + [HttpGet("{id}")] + public async Task> Get(int id) + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.StringGetAsync($"{id}"); + + + if (!result.HasValue) + { + var value = await _db.ProjectDateTimeEntries.FindAsync(id); + await cache.StringSetAsync($"{id}", JsonConvert.SerializeObject(value)); + return value; + } + else + { + return JsonConvert.DeserializeObject(result); + } + } + + // POST api/values + [HttpPost] + public async Task Post([FromBody] ProjectDateTime value) + { + await _db.ProjectDateTimeEntries.AddAsync(value); + await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // PUT api/values/5 + [HttpPut("{id}")] + public async Task Put(int id, [FromBody] ProjectDateTime value) + { + var entry = await _db.ProjectDateTimeEntries.FindAsync(id); + entry = value; + await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var entry = await _db.ProjectDateTimeEntries.FindAsync(id); + _db.ProjectDateTimeEntries.Remove(entry); + await _db.SaveChangesAsync(); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Controllers/ProjectDetailsController.cs b/src/MyTimesheet/MyTimesheet/Controllers/ProjectDetailsController.cs new file mode 100644 index 0000000..e627670 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Controllers/ProjectDetailsController.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using MyTimesheet.Models; +using Microsoft.Extensions.Configuration; +using StackExchange.Redis; +using Newtonsoft.Json; + +namespace MyTimesheet.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ProjectDetailsController : ControllerBase + { + private readonly TimesheetContext _db; + private readonly IConfiguration _config; + private Lazy lazy; + string cacheConnection; + + public ProjectDetailsController(TimesheetContext context, IConfiguration config) + { + _db = context; + _config = config; + cacheConnection = _config.GetValue("CacheConnection").ToString(); + lazy = new Lazy(() => + { + return ConnectionMultiplexer.Connect(cacheConnection); + }); + } + + // GET api/values + [HttpGet] + public async Task>> Get() + { + try + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.ExecuteAsync("KEYS", "*"); + return JsonConvert.DeserializeObject>(result.ToString()); + } + catch (Exception e) + { + return await _db.ProjectDetailsEntries.ToListAsync(); + } + } + + // GET api/values/5 + [HttpGet("{id}")] + public async Task> Get(int id) + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.StringGetAsync($"{id}"); + + + if (!result.HasValue) + { + var value = await _db.ProjectDetailsEntries.FindAsync(id); + await cache.StringSetAsync($"{id}", JsonConvert.SerializeObject(value)); + return value; + } + else + { + return JsonConvert.DeserializeObject(result); + } + } + + // POST api/values + [HttpPost] + public async Task Post([FromBody] ProjectDetails value) + { + await _db.ProjectDetailsEntries.AddAsync(value); + await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // PUT api/values/5 + [HttpPut("{id}")] + public async Task Put(int id, [FromBody] ProjectDetails value) + { + var entry = await _db.ProjectDetailsEntries.FindAsync(id); + entry = value; + await _db.SaveChangesAsync(); + + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public async Task Delete(int id) + { + var entry = await _db.ProjectDetailsEntries.FindAsync(id); + _db.ProjectDetailsEntries.Remove(entry); + await _db.SaveChangesAsync(); + } + } + +} \ No newline at end of file diff --git a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs index b2f5a7c..cf6602c 100644 --- a/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs +++ b/src/MyTimesheet/MyTimesheet/Controllers/TimesheetController.cs @@ -5,6 +5,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using StackExchange.Redis; +using Newtonsoft.Json; +using Microsoft.Extensions.Configuration; namespace MyTimesheet.Controllers { @@ -13,23 +16,55 @@ namespace MyTimesheet.Controllers public class TimesheetController : ControllerBase { private readonly TimesheetContext _db; - public TimesheetController(TimesheetContext context) + private readonly IConfiguration _config; + private Lazy lazy; + string cacheConnection; + + public TimesheetController(TimesheetContext context, IConfiguration config) { _db = context; + _config = config; + cacheConnection = _config.GetValue("CacheConnection").ToString(); + lazy = new Lazy(() => + { + return ConnectionMultiplexer.Connect(cacheConnection); + }); } // GET api/values [HttpGet] public async Task>> Get() { - return await _db.Entries.ToListAsync(); + try + { + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.ExecuteAsync("KEYS", "*"); + return JsonConvert.DeserializeObject>(result.ToString()); + } + catch (Exception e) + { + return await _db.Entries.ToListAsync(); + } } // GET api/values/5 [HttpGet("{id}")] public async Task> Get(int id) { - return await _db.Entries.FindAsync(id); + IDatabase cache = lazy.Value.GetDatabase(); + var result = await cache.StringGetAsync($"{id}"); + + + if (!result.HasValue) + { + var value = await _db.Entries.FindAsync(id); + await cache.StringSetAsync($"{id}", JsonConvert.SerializeObject(value)); + return value; + } + else + { + return JsonConvert.DeserializeObject(result); + } } // POST api/values @@ -38,6 +73,12 @@ public async Task Post([FromBody] TimesheetEntry value) { await _db.Entries.AddAsync(value); await _db.SaveChangesAsync(); + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); } // PUT api/values/5 @@ -47,6 +88,13 @@ public async Task Put(int id, [FromBody] TimesheetEntry value) var entry = await _db.Entries.FindAsync(id); entry = value; await _db.SaveChangesAsync(); + + + IDatabase cache = lazy.Value.GetDatabase(); + var json = JsonConvert.SerializeObject(value); + + await cache.StringSetAsync($"{value.Id}", json); + lazy.Value.Dispose(); } // DELETE api/values/5 diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190122084236_InitialMigration.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122084236_InitialMigration.Designer.cs new file mode 100644 index 0000000..b2e01d4 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122084236_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("20190122084236_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/20190122084236_InitialMigration.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190122084236_InitialMigration.cs new file mode 100644 index 0000000..bd41006 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190122084236_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/20190126174238_first attempt to data normalizing.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126174238_first attempt to data normalizing.Designer.cs new file mode 100644 index 0000000..3f20335 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126174238_first attempt to data normalizing.Designer.cs @@ -0,0 +1,110 @@ +// +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("20190126174238_first attempt to data normalizing")] + partial class firstattempttodatanormalizing + { + 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("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("DeveloperEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDateTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Date"); + + b.Property("Duration"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.ToTable("ProjectDateTimeEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client"); + + b.Property("Description"); + + b.Property("Project"); + + b.HasKey("Id"); + + b.ToTable("ProjectDetailsEntries"); + }); + + 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/20190126174238_first attempt to data normalizing.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126174238_first attempt to data normalizing.cs new file mode 100644 index 0000000..8728587 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126174238_first attempt to data normalizing.cs @@ -0,0 +1,70 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class firstattempttodatanormalizing : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "DeveloperEntries", + 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_DeveloperEntries", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProjectDateTimeEntries", + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_ProjectDateTimeEntries", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProjectDetailsEntries", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + Client = table.Column(nullable: true), + Project = table.Column(nullable: true), + Description = table.Column(nullable: true), + Billable = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProjectDetailsEntries", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DeveloperEntries"); + + migrationBuilder.DropTable( + name: "ProjectDateTimeEntries"); + + migrationBuilder.DropTable( + name: "ProjectDetailsEntries"); + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.Designer.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.Designer.cs new file mode 100644 index 0000000..7551c9e --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.Designer.cs @@ -0,0 +1,79 @@ +// +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("20190126180936_data normalized without entries table")] + partial class datanormalizedwithoutentriestable + { + 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("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("DeveloperEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDateTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Date"); + + b.Property("Duration"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.ToTable("ProjectDateTimeEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client"); + + b.Property("Description"); + + b.Property("Project"); + + b.HasKey("Id"); + + b.ToTable("ProjectDetailsEntries"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.cs b/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.cs new file mode 100644 index 0000000..334d9c8 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/20190126180936_data normalized without entries table.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace MyTimesheet.Migrations +{ + public partial class datanormalizedwithoutentriestable : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Entries"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + 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 new file mode 100644 index 0000000..dbdc498 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Migrations/TimesheetContextModelSnapshot.cs @@ -0,0 +1,77 @@ +// +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.Developer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Name"); + + b.Property("Surname"); + + b.HasKey("Id"); + + b.ToTable("DeveloperEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDateTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Date"); + + b.Property("Duration"); + + b.Property("TimeEnd"); + + b.Property("TimeStart"); + + b.HasKey("Id"); + + b.ToTable("ProjectDateTimeEntries"); + }); + + modelBuilder.Entity("MyTimesheet.Models.ProjectDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Billable"); + + b.Property("Client"); + + b.Property("Description"); + + b.Property("Project"); + + b.HasKey("Id"); + + b.ToTable("ProjectDetailsEntries"); + }); +#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..df051ab --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/Developer.cs @@ -0,0 +1,14 @@ +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; } + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/ProjectDateTime.cs b/src/MyTimesheet/MyTimesheet/Models/ProjectDateTime.cs new file mode 100644 index 0000000..93c9a54 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/ProjectDateTime.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class ProjectDateTime + { + public int Id { get; set; } + public DateTime Date { get; set; } + public DateTime TimeStart { get; set; } + public DateTime TimeEnd { get; set; } + public int Duration { get; set; } + + } +} diff --git a/src/MyTimesheet/MyTimesheet/Models/ProjectDetails.cs b/src/MyTimesheet/MyTimesheet/Models/ProjectDetails.cs new file mode 100644 index 0000000..daa04c6 --- /dev/null +++ b/src/MyTimesheet/MyTimesheet/Models/ProjectDetails.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyTimesheet.Models +{ + public class ProjectDetails + { + public int Id { get; set; } + public string Client { get; set; } + public string Project { 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..7ca0005 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 DeveloperEntries { get; set; } + public DbSet ProjectDateTimeEntries { get; set; } + public DbSet ProjectDetailsEntries { get; set; } } } diff --git a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs index 8c65667..5afe53e 100644 --- a/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs +++ b/src/MyTimesheet/MyTimesheet/Models/TimesheetEntry.cs @@ -13,17 +13,20 @@ public class TimesheetEntry John | Doe | Client X | Website | 2019-01-22 | 09:00 | 11:00 | 120 | I was rocking HTML5 | YES 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; } + //Exercise normalize the database + + 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; } } + + } diff --git a/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj b/src/MyTimesheet/MyTimesheet/MyTimesheet.csproj index 54dfccf..a636127 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..eb3c60c 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.Gift.Langa;User Id=GiftLanga;Password=G4tDB__Xcs;"; 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=" }