diff --git a/HanyadikHetVan/Controllers/PauseController.cs b/HanyadikHetVan/Controllers/PauseController.cs deleted file mode 100644 index 5067a0e..0000000 --- a/HanyadikHetVan/Controllers/PauseController.cs +++ /dev/null @@ -1,73 +0,0 @@ -using HanyadikHetVan.Data.Entities; -using HanyadikHetVan.Services; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using System; -using System.Threading.Tasks; - -namespace HanyadikHetVan.Controllers -{ - [Route("api/pauses")] - [ApiController] - public class PauseController - { - private readonly PauseService _pauseService; - - public PauseController(PauseService pauseService) - { - _pauseService = pauseService; - } - [HttpPost] - public async Task AddPause([FromBody] Pause pause) - { - try - { - await _pauseService.AddPause(pause); - return true; - } - catch (Exception) - { - - return false; - } - } - [HttpDelete("{pauseId}")] - public bool DeletePause(int pauseId) - { - try - { - _pauseService.DeletePause(pauseId); - return true; - } - catch (Exception) - { - return false; - } - } - [HttpPut] - public bool UpdatePause([FromBody] Pause pause) - { - try - { - _pauseService.UpdatePause(pause); - return true; - } - catch (Exception) - { - return false; - } - } - [HttpGet] - public Object GetAllPauses() - { - var data = _pauseService.GetAllPauses(); - var json = JsonConvert.SerializeObject(data, Formatting.Indented, - new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - } - ); - return json; - } - } -} diff --git a/HanyadikHetVan/Controllers/TestController.cs b/HanyadikHetVan/Controllers/TestController.cs deleted file mode 100644 index f62c482..0000000 --- a/HanyadikHetVan/Controllers/TestController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace HanyadikHetVan.Controllers -{ - [Route("api/test")] - [ApiController] - public class TestController : ControllerBase - { - [HttpGet("unprotected")] - public string Unprotected() - { - - return "Unprotected"; - } - - [Authorize] - [HttpGet("protected")] - public string Protected() - { - - return "Protected"; - } - } -} diff --git a/HanyadikHetVan/Controllers/UserController.cs b/HanyadikHetVan/Controllers/UserController.cs deleted file mode 100644 index 7aff46e..0000000 --- a/HanyadikHetVan/Controllers/UserController.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace HanyadikHetVan.Controllers -{ - public class UserController - { - } -} diff --git a/HanyadikHetVan/Controllers/HanyadikHetVanController.cs b/HanyadikHetVan/Controllers/V1/HanyadikHetVanController.cs similarity index 70% rename from HanyadikHetVan/Controllers/HanyadikHetVanController.cs rename to HanyadikHetVan/Controllers/V1/HanyadikHetVanController.cs index 8a33fec..2b59937 100644 --- a/HanyadikHetVan/Controllers/HanyadikHetVanController.cs +++ b/HanyadikHetVan/Controllers/V1/HanyadikHetVanController.cs @@ -1,12 +1,14 @@ using HanyadikHetVan.DTO; using HanyadikHetVan.Services; using Microsoft.AspNetCore.Mvc; +using System.Net.Mime; -namespace HanyadikHetVan.Controllers +namespace HanyadikHetVan.Controllers.V1 { [ApiController] - [Route("api/hanyadikhetvan")] - public class HanyadikHetVanController : ControllerBase + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]")] + public class HanyadikHetVanController : Controller { private readonly HanyadikHetVanJsonService _jsonservice; @@ -20,7 +22,8 @@ namespace HanyadikHetVan.Controllers } [HttpGet("json")] - [Consumes("application/json")] + [Consumes(MediaTypeNames.Application.Json)] + [Produces(MediaTypeNames.Application.Json)] public HanyadikHetVanDTO GetJson() { return _jsonservice.HanyadikHetVan(); diff --git a/HanyadikHetVan/Controllers/V1/TestController.cs b/HanyadikHetVan/Controllers/V1/TestController.cs new file mode 100644 index 0000000..f82addb --- /dev/null +++ b/HanyadikHetVan/Controllers/V1/TestController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Security.Claims; + +namespace HanyadikHetVan.Controllers.V1 +{ + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiController] + public class TestController : Controller + { + private UserManager _userManager; + + public TestController(UserManager userManager) + { + _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); + } + + [HttpGet("unprotected")] + [Produces("application/json")] + public string Unprotected() + { + + return "Unprotected"; + } + + [Authorize] + [HttpGet("protected")] + [Produces("application/json")] + public string Protected() + { + return this.User.FindFirst(ClaimTypes.NameIdentifier).Value; + } + } +} diff --git a/HanyadikHetVan/Controllers/V2/HanyadikHetVanController.cs b/HanyadikHetVan/Controllers/V2/HanyadikHetVanController.cs new file mode 100644 index 0000000..511266c --- /dev/null +++ b/HanyadikHetVan/Controllers/V2/HanyadikHetVanController.cs @@ -0,0 +1,53 @@ +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers.V2 +{ + [ApiController] + [ApiVersion("2.0")] + [Route("api/v{version:apiVersion}/[controller]")] + public class HanyadikHetVanController : Controller + { + private readonly HanyadikHetVanEntityService _hanyadikHetVanEntityService; + + public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService) + { + _hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService)); + } + + [HttpGet("{weeklytimespanId}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetWeekById(int weeklytimespanId) + { + try + { + var wts = await _hanyadikHetVanEntityService.GetWeekById(weeklytimespanId); + return Ok(wts); + } + catch (Exception) + { + return BadRequest(); + } + } + + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task GetDefaultWeek() + { + try + { + var wts = await _hanyadikHetVanEntityService.GetDefaultWeek(); + return Ok(wts); + } + catch (Exception) + { + return BadRequest(); + } + } + } +} diff --git a/HanyadikHetVan/Controllers/V2/PauseController.cs b/HanyadikHetVan/Controllers/V2/PauseController.cs new file mode 100644 index 0000000..6d82eaf --- /dev/null +++ b/HanyadikHetVan/Controllers/V2/PauseController.cs @@ -0,0 +1,100 @@ +using HanyadikHetVan.DTO; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Net.Mime; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers.V2 +{ + [ApiVersion("2.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiController] + public class PauseController : Controller + { + private readonly PauseService _pauseService; + + public PauseController(PauseService pauseService) + { + _pauseService = pauseService; + } + [HttpPost] + [Authorize] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task AddPause([FromBody] PauseDTO pause) + { + try + { + var obj = await _pauseService.AddPause(pause); + return CreatedAtAction(nameof(GetPauseById),new { pauseId = obj.Id } ,obj); + } + catch (Exception) + { + + return BadRequest(); + } + } + [HttpDelete("{pauseId}")] + [Authorize] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task DeletePause(int pauseId) + { + var result = await _pauseService.DeletePause(pauseId); + if (result) + { + return Ok(result); + } + else + { + return NotFound(); + } + } + [HttpPut] + [Authorize] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PauseDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task UpdatePause([FromBody] PauseDTO pause) + { + try + { + var obj = await _pauseService.UpdatePause(pause); + return Ok(obj); + } + catch (Exception) + { + return NotFound(); + } + } + [HttpGet] + public async Task> GetAllPauses() + { + return await _pauseService.GetAllPauses(); + } + + [HttpGet("{pauseId}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PauseDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetPauseById(int pauseId) + { + var pause = await _pauseService.GetPause(pauseId); + if (pause == null) + { + return NotFound(); + } + else + { + return Ok(pause); + } + } + } +} diff --git a/HanyadikHetVan/Controllers/V2/PurseController.cs b/HanyadikHetVan/Controllers/V2/PurseController.cs new file mode 100644 index 0000000..b881acc --- /dev/null +++ b/HanyadikHetVan/Controllers/V2/PurseController.cs @@ -0,0 +1,63 @@ +using HanyadikHetVan.DTO; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers.V2 +{ + [ApiVersion("2.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiController] + public class PurseController : Controller + { + private readonly PurseService _purseService; + + public PurseController(PurseService purseService) + { + _purseService = purseService ?? throw new ArgumentNullException(nameof(purseService)); + } + + [HttpPut("{userId}")] + [Authorize] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PurseDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task SetBalanceOfUser(string userId, [FromBody] PurseDTO pause) + { + try + { + var obj = await _purseService.SetBalanceOfUser(userId, pause.Balance); + return Ok(obj); + } + catch (Exception) + { + return NotFound(); + } + } + + [HttpGet("{userId}")] + [Authorize] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PurseDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task GetPauseById(string userId) + { + var purse = await _purseService.GetBalanceOfUser(userId); + if (purse == null) + { + return NotFound(); + } + else + { + return Ok(purse); + } + } + } +} diff --git a/HanyadikHetVan/Controllers/V2/WeeklyTimeSpanController.cs b/HanyadikHetVan/Controllers/V2/WeeklyTimeSpanController.cs new file mode 100644 index 0000000..9fc3808 --- /dev/null +++ b/HanyadikHetVan/Controllers/V2/WeeklyTimeSpanController.cs @@ -0,0 +1,129 @@ +using HanyadikHetVan.DTO; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Net.Mime; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers.V2 +{ + [ApiVersion("2.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiController] + public class WeeklyTimeSpanController: Controller + { + private readonly WeeklyTimeSpanService _weeklytimespanService; + + public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService) + { + _weeklytimespanService = weeklytimespanService; + } + [HttpPost] + [Authorize] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task AddWeeklyTimeSpan([FromBody] WeeklyTimeSpanDTO weeklytimespan) + { + try + { + var obj = await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan); + return CreatedAtAction(nameof(GetWeeklyTimeSpanById), new { weeklytimespanId = obj.Id }, obj); + } + catch (Exception) + { + + return BadRequest(); + } + } + [HttpDelete("{weeklyTimeSpanId}")] + [Authorize] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task DeleteWeeklyTimeSpan(int weeklyTimeSpanId) + { + var result = await _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId); + if (result) + { + return Ok(result); + } + else + { + return NotFound(); + } + } + [HttpPut] + [Authorize] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpanDTO weeklytimespan) + { + try + { + var wts = await _weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan); + return Ok(wts); + } + catch (Exception) + { + return NotFound(); + } + } + [HttpGet("date/{startTime}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetAllWeeklyTimeSpanByStartdate(DateTime startTime) + { + var wts = await _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime); + if (wts == null) + { + return NotFound(); + } + else + { + return Ok(wts); + } + } + [HttpGet] + public async Task> GetAllWeeklyTimespans() + { + return await _weeklytimespanService.GetAllWeeklyTimeSpans(); + } + [HttpGet("{weeklytimespanId}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetWeeklyTimeSpanById(int weeklytimespanId) + { + var wts = await _weeklytimespanService.GetWeeklyTimeSpan(weeklytimespanId); + if (wts == null) + { + return NotFound(); + } + else + { + return Ok(wts); + } + } + [HttpGet("pauses/{weeklytimespanId}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetAllPausesOfTimeSpan(int weeklytimespanId) + { + var wts = await _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId); + if (wts == null) + { + return NotFound(); + } + else + { + return Ok(wts); + } + } + } +} diff --git a/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs b/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs deleted file mode 100644 index f8f15f0..0000000 --- a/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs +++ /dev/null @@ -1,101 +0,0 @@ -using HanyadikHetVan.Data.Entities; -using HanyadikHetVan.Services; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; -using System; -using System.Threading.Tasks; - -namespace HanyadikHetVan.Controllers -{ - [Route("api/weeklytimespans")] - [ApiController] - public class WeeklyTimeSpanController - { - private readonly WeeklyTimeSpanService _weeklytimespanService; - - public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService) - { - _weeklytimespanService = weeklytimespanService; - } - [HttpPost] - public async Task AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) - { - try - { - var obj = await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan); - return obj; - } - catch (Exception) - { - - return false; - } - } - [HttpDelete("{weeklyTimeSpanId}")] - public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId) - { - return _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId); - } - [HttpPut] - public bool UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) - { - try - { - _weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan); - return true; - } - catch (Exception) - { - return false; - } - } - [HttpGet("date/{startTime}")] - public Object GetAllWeeklyTimeSpanByStartdate(DateTime startTime) - { - var data = _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime); - var json = JsonConvert.SerializeObject(data, Formatting.Indented, - new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - } - ); - return json; - } - [HttpGet] - public Object GetAllWeeklyTimespans() - { - var data = _weeklytimespanService.GetAllWeeklyTimeSpans(); - var json = JsonConvert.SerializeObject(data, Formatting.Indented, - new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - } - ); - return json; - } - [HttpGet("{weeklytimespanId}")] - public Object GetWeeklyTimeSpanById(int weeklytimespanId) - { - var data = _weeklytimespanService.GetWeeklyTimeSpan(weeklytimespanId); - var json = JsonConvert.SerializeObject(data, Formatting.Indented, - new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - } - ); - return json; - } - [HttpGet("pauses/{weeklytimespanId}")] - public Object GetAllPausesOfTimeSpan(int weeklytimespanId) - { - var data = _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId); - var json = JsonConvert.SerializeObject(data, Formatting.Indented, - new JsonSerializerSettings() - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - } - ); - return json; - } - } -} diff --git a/HanyadikHetVan/DTO/PauseDTO.cs b/HanyadikHetVan/DTO/PauseDTO.cs new file mode 100644 index 0000000..307d980 --- /dev/null +++ b/HanyadikHetVan/DTO/PauseDTO.cs @@ -0,0 +1,12 @@ +using System; + +namespace HanyadikHetVan.DTO +{ + public class PauseDTO + { + public int Id { get; set; } + public int WeeklyTimeSpanId { get; set; } + public DateTime Startdate { get; set; } + public DateTime Enddate { get; set; } + } +} diff --git a/HanyadikHetVan/DTO/PurseDTO.cs b/HanyadikHetVan/DTO/PurseDTO.cs new file mode 100644 index 0000000..4fb6350 --- /dev/null +++ b/HanyadikHetVan/DTO/PurseDTO.cs @@ -0,0 +1,7 @@ +namespace HanyadikHetVan.DTO +{ + public class PurseDTO + { + public int Balance { get; set; } + } +} diff --git a/HanyadikHetVan/DTO/WeeklyTimeSpanDTO.cs b/HanyadikHetVan/DTO/WeeklyTimeSpanDTO.cs new file mode 100644 index 0000000..e0692bb --- /dev/null +++ b/HanyadikHetVan/DTO/WeeklyTimeSpanDTO.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.DTO +{ + public class WeeklyTimeSpanDTO + { + public int Id { get; set; } + public DateTime Startdate { get; set; } + + public virtual ICollection Pauses { get; set; } + + public int CurrentWeek + { + get + { + TimeSpan allPause = this.Pauses.Aggregate(TimeSpan.Zero, (sumSoFar, nextPause) => sumSoFar + (nextPause.Enddate - nextPause.Startdate)); + + TimeSpan wtsLength = DateTime.Now - this.Startdate; + + return (wtsLength - allPause).Days / 7; + } + } + } +} diff --git a/HanyadikHetVan/Data/ApplicationDbContext.cs b/HanyadikHetVan/Data/ApplicationDbContext.cs index 2a1b088..ff82278 100644 --- a/HanyadikHetVan/Data/ApplicationDbContext.cs +++ b/HanyadikHetVan/Data/ApplicationDbContext.cs @@ -9,6 +9,8 @@ namespace HanyadikHetVan.Data public DbSet Pauses { get; set; } public DbSet WeeklyTimeSpans { get; set; } + public DbSet Purses { get; set; } + public ApplicationDbContext(DbContextOptions options) : base(options) { diff --git a/HanyadikHetVan/Data/Entities/Pause.cs b/HanyadikHetVan/Data/Entities/Pause.cs index f68fa10..1f24670 100644 --- a/HanyadikHetVan/Data/Entities/Pause.cs +++ b/HanyadikHetVan/Data/Entities/Pause.cs @@ -1,13 +1,21 @@ -using System; +using HanyadikHetVan.DTO; +using System; +using System.ComponentModel.DataAnnotations; namespace HanyadikHetVan.Data.Entities { public class Pause { public int Id { get; set; } + public int WeeklyTimeSpanId { get; set; } + public virtual WeeklyTimeSpan WeeklyTimeSpan { get; set; } + + [Required] public DateTime Startdate { get; set; } + + [Required] public DateTime Enddate { get; set; } } } diff --git a/HanyadikHetVan/Data/Entities/Purse.cs b/HanyadikHetVan/Data/Entities/Purse.cs new file mode 100644 index 0000000..d251ae6 --- /dev/null +++ b/HanyadikHetVan/Data/Entities/Purse.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Data.Entities +{ + public class Purse + { + public int Id { get; set; } + + public virtual IdentityUser User { get; set; } + + public String UserId { get; set; } + + public int Balance { get; set; } + } +} diff --git a/HanyadikHetVan/Data/Entities/WeeklyTimeSpan.cs b/HanyadikHetVan/Data/Entities/WeeklyTimeSpan.cs index 868aa60..0a41f5c 100644 --- a/HanyadikHetVan/Data/Entities/WeeklyTimeSpan.cs +++ b/HanyadikHetVan/Data/Entities/WeeklyTimeSpan.cs @@ -1,13 +1,21 @@ -using System; +using Microsoft.AspNetCore.Identity; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace HanyadikHetVan.Data.Entities { public class WeeklyTimeSpan { public int Id { get; set; } + + [Required] public DateTime Startdate { get; set; } public virtual ICollection Pauses { get; set; } + + public virtual IdentityUser Owner { get; set; } + + public String OwnerId { get; set; } } } diff --git a/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.Designer.cs b/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.Designer.cs new file mode 100644 index 0000000..91093c9 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.Designer.cs @@ -0,0 +1,345 @@ +// +using System; +using HanyadikHetVan.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace HanyadikHetVan.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210518232039_AddOwnerToWeeklyTimeSpan")] + partial class AddOwnerToWeeklyTimeSpan + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Enddate") + .HasColumnType("datetime2"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("Pauses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OwnerId") + .HasColumnType("nvarchar(450)"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("Pauses") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Navigation("Pauses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.cs b/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.cs new file mode 100644 index 0000000..1d59029 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210518232039_AddOwnerToWeeklyTimeSpan.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace HanyadikHetVan.Data.Migrations +{ + public partial class AddOwnerToWeeklyTimeSpan : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "OwnerId", + table: "WeeklyTimeSpans", + type: "nvarchar(450)", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_WeeklyTimeSpans_OwnerId", + table: "WeeklyTimeSpans", + column: "OwnerId"); + + migrationBuilder.AddForeignKey( + name: "FK_WeeklyTimeSpans_AspNetUsers_OwnerId", + table: "WeeklyTimeSpans", + column: "OwnerId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_WeeklyTimeSpans_AspNetUsers_OwnerId", + table: "WeeklyTimeSpans"); + + migrationBuilder.DropIndex( + name: "IX_WeeklyTimeSpans_OwnerId", + table: "WeeklyTimeSpans"); + + migrationBuilder.DropColumn( + name: "OwnerId", + table: "WeeklyTimeSpans"); + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.Designer.cs b/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.Designer.cs new file mode 100644 index 0000000..0198085 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.Designer.cs @@ -0,0 +1,348 @@ +// +using System; +using HanyadikHetVan.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace HanyadikHetVan.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210519014822_AddPruse")] + partial class AddPruse + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Enddate") + .HasColumnType("datetime2"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("Pauses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OwnerId") + .HasColumnType("nvarchar(450)"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("Pauses") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Navigation("Pauses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.cs b/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.cs new file mode 100644 index 0000000..d6a2874 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519014822_AddPruse.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace HanyadikHetVan.Data.Migrations +{ + public partial class AddPruse : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Price", + table: "WeeklyTimeSpans", + type: "int", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Price", + table: "WeeklyTimeSpans"); + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.Designer.cs b/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.Designer.cs new file mode 100644 index 0000000..300674d --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.Designer.cs @@ -0,0 +1,345 @@ +// +using System; +using HanyadikHetVan.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace HanyadikHetVan.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210519014936_RemovePrice")] + partial class RemovePrice + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Enddate") + .HasColumnType("datetime2"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("Pauses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OwnerId") + .HasColumnType("nvarchar(450)"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("Pauses") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Navigation("Pauses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.cs b/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.cs new file mode 100644 index 0000000..6956729 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519014936_RemovePrice.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace HanyadikHetVan.Data.Migrations +{ + public partial class RemovePrice : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Price", + table: "WeeklyTimeSpans"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Price", + table: "WeeklyTimeSpans", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.Designer.cs b/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.Designer.cs new file mode 100644 index 0000000..13375d3 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.Designer.cs @@ -0,0 +1,374 @@ +// +using System; +using HanyadikHetVan.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace HanyadikHetVan.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210519022840_AddPurseToContext")] + partial class AddPurseToContext + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Enddate") + .HasColumnType("datetime2"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("Pauses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Purse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Balance") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OwnerId") + .HasColumnType("nvarchar(450)"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("Pauses") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Purse", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Navigation("Pauses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.cs b/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.cs new file mode 100644 index 0000000..650df7b --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519022840_AddPurseToContext.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace HanyadikHetVan.Data.Migrations +{ + public partial class AddPurseToContext : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Purses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: true), + Balance = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Purses", x => x.Id); + table.ForeignKey( + name: "FK_Purses_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Purses_UserId", + table: "Purses", + column: "UserId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Purses"); + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 0504feb..d676c4d 100644 --- a/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -16,7 +16,7 @@ namespace HanyadikHetVan.Data.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.5") + .HasAnnotation("ProductVersion", "5.0.6") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => @@ -42,6 +42,26 @@ namespace HanyadikHetVan.Data.Migrations b.ToTable("Pauses"); }); + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Purse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Balance") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purses"); + }); + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => { b.Property("Id") @@ -49,11 +69,16 @@ namespace HanyadikHetVan.Data.Migrations .HasColumnType("int") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("OwnerId") + .HasColumnType("nvarchar(450)"); + b.Property("Startdate") .HasColumnType("datetime2"); b.HasKey("Id"); + b.HasIndex("OwnerId"); + b.ToTable("WeeklyTimeSpans"); }); @@ -268,6 +293,24 @@ namespace HanyadikHetVan.Data.Migrations b.Navigation("WeeklyTimeSpan"); }); + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Purse", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) diff --git a/HanyadikHetVan/HanyadikHetVan.csproj b/HanyadikHetVan/HanyadikHetVan.csproj index 679145a..5aa09ff 100644 --- a/HanyadikHetVan/HanyadikHetVan.csproj +++ b/HanyadikHetVan/HanyadikHetVan.csproj @@ -7,13 +7,20 @@ + + + - - - - - - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/HanyadikHetVan/Profiles/PauseProfile.cs b/HanyadikHetVan/Profiles/PauseProfile.cs new file mode 100644 index 0000000..0d7bf26 --- /dev/null +++ b/HanyadikHetVan/Profiles/PauseProfile.cs @@ -0,0 +1,19 @@ +using AutoMapper; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Profiles +{ + public class PauseProfile : Profile + { + public PauseProfile() + { + CreateMap(); + CreateMap().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()); + } + } +} diff --git a/HanyadikHetVan/Profiles/PurseProfile.cs b/HanyadikHetVan/Profiles/PurseProfile.cs new file mode 100644 index 0000000..87bde18 --- /dev/null +++ b/HanyadikHetVan/Profiles/PurseProfile.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; + +namespace HanyadikHetVan.Profiles +{ + public class PurseProfile : Profile + { + public PurseProfile() + { + CreateMap(); + CreateMap().ForMember(x => x.User, options => options.Ignore()).ForMember(x => x.UserId, options => options.Ignore()).ForMember(x => x.Id, options => options.Ignore()); + } + } +} diff --git a/HanyadikHetVan/Profiles/WeeklyTimeSpanProfile.cs b/HanyadikHetVan/Profiles/WeeklyTimeSpanProfile.cs new file mode 100644 index 0000000..4b74d95 --- /dev/null +++ b/HanyadikHetVan/Profiles/WeeklyTimeSpanProfile.cs @@ -0,0 +1,19 @@ +using AutoMapper; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Profiles +{ + public class WeeklyTimeSpanProfile : Profile + { + public WeeklyTimeSpanProfile() + { + CreateMap(); + CreateMap().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.Owner, options => options.Ignore()).ForMember(x => x.OwnerId, options => options.Ignore()); + } + } +} diff --git a/HanyadikHetVan/Services/HanyadikHetVanEntityService.cs b/HanyadikHetVan/Services/HanyadikHetVanEntityService.cs new file mode 100644 index 0000000..2c0010c --- /dev/null +++ b/HanyadikHetVan/Services/HanyadikHetVanEntityService.cs @@ -0,0 +1,37 @@ +using AutoMapper; +using HanyadikHetVan.Data; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Services +{ + public class HanyadikHetVanEntityService + { + private readonly ApplicationDbContext _dbContext; + private readonly IMapper _mapper; + + public HanyadikHetVanEntityService(ApplicationDbContext dbContext, IMapper mapper) + { + _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); + _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); + } + + public async Task GetDefaultWeek() + { + var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).LastAsync(); + var latestDto = _mapper.Map(latest); + return latestDto.CurrentWeek; + } + + public async Task GetWeekById(int weeklytimespanId) + { + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); + var wtsDto = _mapper.Map(wts); + return wtsDto.CurrentWeek; + } + } +} diff --git a/HanyadikHetVan/Services/PauseService.cs b/HanyadikHetVan/Services/PauseService.cs index e78150c..4e9e0b4 100644 --- a/HanyadikHetVan/Services/PauseService.cs +++ b/HanyadikHetVan/Services/PauseService.cs @@ -1,5 +1,7 @@ -using HanyadikHetVan.Data; +using AutoMapper; +using HanyadikHetVan.Data; using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -11,31 +13,41 @@ namespace HanyadikHetVan.Services public class PauseService { private readonly ApplicationDbContext _dbContext; + private readonly IMapper _mapper; - public PauseService(ApplicationDbContext dbContext) + public PauseService(ApplicationDbContext dbContext, IMapper mapper) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); + _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public IEnumerable GetAllPauses() + public async Task> GetAllPauses() { - return _dbContext.Pauses.Include(x => x.WeeklyTimeSpan).ToList(); + var pauses = await _dbContext.Pauses.Include(x => x.WeeklyTimeSpan).ToListAsync(); + return _mapper.Map, List>(pauses); } - public async Task AddPause(Pause pause) + public async Task AddPause(PauseDTO pause) { - var obj = await _dbContext.Pauses.AddAsync(pause); - _dbContext.SaveChanges(); - return obj.Entity; + var pauseEntity = _mapper.Map(pause); + var obj = _dbContext.Pauses.Add(pauseEntity); + await _dbContext.SaveChangesAsync(); + return _mapper.Map(obj.Entity); } - public bool DeletePause(int pauseId) + public async Task GetPause(int pauseId) + { + var pause = await _dbContext.Pauses.Where(x => x.Id == pauseId).FirstOrDefaultAsync(); + return _mapper.Map(pause); + } + + public async Task DeletePause(int pauseId) { try { - var item = _dbContext.Pauses.Where(x => x.Id == pauseId).FirstOrDefault(); + var item = await _dbContext.Pauses.Where(x => x.Id == pauseId).FirstOrDefaultAsync(); _dbContext.Pauses.Remove(item); - _dbContext.SaveChanges(); + await _dbContext.SaveChangesAsync(); return true; } catch (Exception) @@ -44,22 +56,14 @@ namespace HanyadikHetVan.Services } } - public bool UpdatePause(Pause pause) + public async Task UpdatePause(PauseDTO pause) { - try - { - var DataList = _dbContext.Pauses.ToList(); - foreach (var item in DataList) - { - _dbContext.Pauses.Update(item); - _dbContext.SaveChanges(); - } - return true; - } - catch (Exception) - { - return true; - } + var pauseEntity = _mapper.Map(pause); + pauseEntity.Id = pause.Id; + _dbContext.Pauses.Update(pauseEntity); + await _dbContext.SaveChangesAsync(); + var newPause = await _dbContext.Pauses.Where(x => x.Id == pause.Id).FirstOrDefaultAsync(); + return _mapper.Map(newPause); } } } diff --git a/HanyadikHetVan/Services/PurseService.cs b/HanyadikHetVan/Services/PurseService.cs new file mode 100644 index 0000000..d933de7 --- /dev/null +++ b/HanyadikHetVan/Services/PurseService.cs @@ -0,0 +1,39 @@ +using AutoMapper; +using HanyadikHetVan.Data; +using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Services +{ + public class PurseService + { + private readonly ApplicationDbContext _dbContext; + private readonly IMapper _mapper; + + public PurseService(ApplicationDbContext dbContext, IMapper mapper) + { + _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); + _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); + } + + public async Task GetBalanceOfUser(String userId) + { + var purse = await _dbContext.Purses.Where(x => x.UserId == userId).FirstOrDefaultAsync(); + return _mapper.Map(purse); + } + + public async Task SetBalanceOfUser(String userId, int newBalance) + { + var purse = new Purse() { UserId = userId, Balance = newBalance }; + _dbContext.Purses.Update(purse); + await _dbContext.SaveChangesAsync(); + var newPurse = await _dbContext.Purses.Where(x => x.UserId == userId).FirstOrDefaultAsync(); + return _mapper.Map(newPurse); + } + } +} diff --git a/HanyadikHetVan/Services/WeeklyTimeSpanService.cs b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs index de81ec5..7010641 100644 --- a/HanyadikHetVan/Services/WeeklyTimeSpanService.cs +++ b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs @@ -1,5 +1,8 @@ -using HanyadikHetVan.Data; +using AutoMapper; +using AutoMapper.QueryableExtensions; +using HanyadikHetVan.Data; using HanyadikHetVan.Data.Entities; +using HanyadikHetVan.DTO; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -11,46 +14,53 @@ namespace HanyadikHetVan.Services public class WeeklyTimeSpanService { private readonly ApplicationDbContext _dbContext; + private readonly IMapper _mapper; - public WeeklyTimeSpanService(ApplicationDbContext dbContext) + public WeeklyTimeSpanService(ApplicationDbContext dbContext, IMapper mapper) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); + _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public IEnumerable GetAllWeeklyTimeSpans() + public async Task> GetAllWeeklyTimeSpans() { - return _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).ToList(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).ToListAsync(); + return _mapper.Map, List>(wts); } - public WeeklyTimeSpan GetWeeklyTimeSpan(int weeklytimespanId) + public async Task GetWeeklyTimeSpan(int weeklytimespanId) { - return _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefault(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); + return _mapper.Map(wts); } - public ICollection GetPausesOfWeeklyTimeSpan(int weeklytimespanId) + public async Task> GetPausesOfWeeklyTimeSpan(int weeklytimespanId) { - return _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefault().Pauses; + var pauses = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); + return _mapper.Map, List>(pauses.Pauses); } - public IEnumerable GetWeeklyTimeSpanByStartdate(DateTime startTime) + public async Task GetWeeklyTimeSpanByStartdate(DateTime startTime) { - return _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToList(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToListAsync(); + return _mapper.Map, WeeklyTimeSpanDTO>(wts); } - public async Task AddWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan) + public async Task AddWeeklyTimeSpan(WeeklyTimeSpanDTO weeklytimespan) { - var obj = await _dbContext.WeeklyTimeSpans.AddAsync(weeklytimespan); - _dbContext.SaveChanges(); - return obj.Entity; + var wts = _mapper.Map(weeklytimespan); + var obj = await _dbContext.WeeklyTimeSpans.AddAsync(wts); + await _dbContext.SaveChangesAsync(); + return _mapper.Map(obj.Entity); } - public bool DeleteWeeklyTimeSpan(int weeklytimespanId) + public async Task DeleteWeeklyTimeSpan(int weeklytimespanId) { try { - var item = _dbContext.WeeklyTimeSpans.Where(x => x.Id == weeklytimespanId).FirstOrDefault(); + var item = await _dbContext.WeeklyTimeSpans.Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); _dbContext.WeeklyTimeSpans.Remove(item); - _dbContext.SaveChanges(); + await _dbContext.SaveChangesAsync(); return true; } catch (Exception) @@ -59,22 +69,14 @@ namespace HanyadikHetVan.Services } } - public bool UpdateWeeklyTimeSpan(WeeklyTimeSpan weeklytimespan) + public async Task UpdateWeeklyTimeSpan(WeeklyTimeSpanDTO weeklytimespan) { - try - { - var DataList = _dbContext.WeeklyTimeSpans.ToList(); - foreach (var item in DataList) - { - _dbContext.WeeklyTimeSpans.Update(item); - _dbContext.SaveChanges(); - } - return true; - } - catch (Exception) - { - return true; - } + var wts = _mapper.Map(weeklytimespan); + wts.Id = weeklytimespan.Id; + _dbContext.WeeklyTimeSpans.Update(wts); + await _dbContext.SaveChangesAsync(); + var newwts = await _dbContext.WeeklyTimeSpans.Where(x => x.Id == weeklytimespan.Id).FirstOrDefaultAsync(); + return _mapper.Map(newwts); } } } diff --git a/HanyadikHetVan/Startup.cs b/HanyadikHetVan/Startup.cs index 1a9a176..740b65b 100644 --- a/HanyadikHetVan/Startup.cs +++ b/HanyadikHetVan/Startup.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; +using System.Reflection; namespace HanyadikHetVan { @@ -21,14 +22,16 @@ namespace HanyadikHetVan public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); + services.AddAutoMapper(Assembly.GetExecutingAssembly()); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddDatabaseDeveloperPageExceptionFilter(); @@ -65,13 +68,24 @@ namespace HanyadikHetVan services.AddControllers(); + services.AddApiVersioning(options => + { + options.ReportApiVersions = true; + }); + + services.AddVersionedApiExplorer(options => + { + options.GroupNameFormat = "'v'VVV"; + options.SubstituteApiVersionInUrl = true; + }); + services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v1" }); + c.SwaggerDoc("v2", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v2" }); }); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) @@ -79,7 +93,11 @@ namespace HanyadikHetVan app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "HanyadikHetVan v1")); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("v1/swagger.json", "Original API"); + c.SwaggerEndpoint("v2/swagger.json", "Homework API"); + }); } else { diff --git a/Insomnia.json b/Insomnia.json new file mode 100644 index 0000000..4d70e25 --- /dev/null +++ b/Insomnia.json @@ -0,0 +1 @@ +{"_type":"export","__export_format":4,"__export_date":"2021-05-18T17:38:15.292Z","__export_source":"insomnia.desktop.app:v2021.3.0","resources":[{"_id":"req_d1ce12920703411bb9239086d5eebeaf","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358836406,"created":1621358764056,"url":"","name":"Login","description":"","method":"GET","body":{},"parameters":[],"headers":[{"name":"CLIENT_ID","value":"postman","description":"","id":"pair_15ae3c2fcba54b498cb7a0472a300c03"},{"name":"CLIENT_SECRET","value":"xmYYS/lSPIz5IdbgUXNbp66JYSejHbw7/oFXy7CLk8s=","description":"","id":"pair_792b4774ecc74d1fa6668b34b007966f"},{"name":"","value":"","description":"","id":"pair_02f1429d1c7b4742a50026136ccfb60c"}],"authentication":{},"metaSortKey":-1621358764056,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"wrk_f357700b92cd436684cbaa092faddb11","parentId":null,"modified":1621358491167,"created":1621358491167,"name":"HanyadikHetVan","description":"","scope":"collection","_type":"workspace"},{"_id":"req_87fc2e4796ae4fada37c7669d5b03209","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358697962,"created":1621358525104,"url":"https://127.0.0.1:5001/api/test/unprotected","name":"Test Unprotected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1621358525104,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_deaaea3ec86b436398e5a0bb91547ed6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621359446725,"created":1621358708070,"url":"https://127.0.0.1:5001/api/test/protected","name":"Test Protected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Asdfghjkl0.","username":"valami@valami.com","credentialsInBody":true},"metaSortKey":-1621358525054,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492714,"created":1621358492714,"name":"Base Environment","data":{},"dataPropertyOrder":null,"color":null,"isPrivate":false,"metaSortKey":1621358492715,"_type":"environment"},{"_id":"jar_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492771,"created":1621358492771,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_602f99b584af4a05a041b16758dfd954","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358491227,"created":1621358491227,"fileName":"HanyadikHetVan","contents":"","contentType":"yaml","_type":"api_spec"}]} \ No newline at end of file