diff options
| author | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
| commit | 3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch) | |
| tree | 734ca81d7d0841d8863e3f523ebba14c282dc681 /src/Data | |
| download | fagprove-master.tar.xz fagprove-master.zip | |
Diffstat (limited to 'src/Data')
| -rw-r--r-- | src/Data/AppDbContext.cs | 26 | ||||
| -rw-r--r-- | src/Data/DTOs/CabinDto.cs | 16 | ||||
| -rw-r--r-- | src/Data/DTOs/LoginDto.cs | 8 | ||||
| -rw-r--r-- | src/Data/DTOs/ReservationDto.cs | 15 | ||||
| -rw-r--r-- | src/Data/DTOs/UpdatePasswordDto.cs | 8 | ||||
| -rw-r--r-- | src/Data/DTOs/UserDto.cs | 13 | ||||
| -rw-r--r-- | src/Data/Enums/ReservationStatus.cs | 10 | ||||
| -rw-r--r-- | src/Data/Enums/UserRole.cs | 8 | ||||
| -rw-r--r-- | src/Data/Models/CoreDataModel.cs | 25 | ||||
| -rw-r--r-- | src/Data/Models/Reservation.cs | 15 | ||||
| -rw-r--r-- | src/Data/Models/ReservationObject.cs | 13 | ||||
| -rw-r--r-- | src/Data/Models/User.cs | 15 | ||||
| -rw-r--r-- | src/Data/Seed.cs | 41 | ||||
| -rw-r--r-- | src/Data/StaticData.cs | 43 |
14 files changed, 256 insertions, 0 deletions
diff --git a/src/Data/AppDbContext.cs b/src/Data/AppDbContext.cs new file mode 100644 index 0000000..34aad00 --- /dev/null +++ b/src/Data/AppDbContext.cs @@ -0,0 +1,26 @@ +using IOL.Fagprove.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace IOL.Fagprove.Data +{ + public class AppDbContext : DbContext + { + public AppDbContext(DbContextOptions options) : base(options) + { + } + public DbSet<User> Users { get; set; } + public DbSet<Reservation> Reservations { get; set; } + public DbSet<ReservationObject> Cabins { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { +#if DEBUG + modelBuilder.ApplyConfiguration(new Seed.SeedUsers()); +#endif + modelBuilder.Entity<User>().ToTable("Users"); + modelBuilder.Entity<Reservation>().ToTable("Reservations"); + modelBuilder.Entity<ReservationObject>().ToTable("Cabins"); + base.OnModelCreating(modelBuilder); + } + } +}
\ No newline at end of file diff --git a/src/Data/DTOs/CabinDto.cs b/src/Data/DTOs/CabinDto.cs new file mode 100644 index 0000000..d1c1f8a --- /dev/null +++ b/src/Data/DTOs/CabinDto.cs @@ -0,0 +1,16 @@ +using System; + +namespace IOL.Fagprove.Data.DTOs +{ + public class CabinDto + { + public Guid Id { get; set; } + public string CategoryName { get; set; } + public Guid CategoryId { get; set; } + public string Name { get; set; } + public int? Capacity { get; set; } + public string Price { get; set; } + public string Description { get; set; } + public string Size { get; set; } + } +}
\ No newline at end of file diff --git a/src/Data/DTOs/LoginDto.cs b/src/Data/DTOs/LoginDto.cs new file mode 100644 index 0000000..1b0a4cb --- /dev/null +++ b/src/Data/DTOs/LoginDto.cs @@ -0,0 +1,8 @@ +namespace IOL.Fagprove.Data.DTOs +{ + public class LoginDto + { + public string Username { get; set; } + public string Password { get; set; } + } +}
\ No newline at end of file diff --git a/src/Data/DTOs/ReservationDto.cs b/src/Data/DTOs/ReservationDto.cs new file mode 100644 index 0000000..c3b1480 --- /dev/null +++ b/src/Data/DTOs/ReservationDto.cs @@ -0,0 +1,15 @@ +using System; +using IOL.Fagprove.Data.Enums; + +namespace IOL.Fagprove.Data.DTOs +{ + public class ReservationDto + { + public Guid Id { get; set; } + public string Name { get; set; } + public string From { get; set; } + public string To { get; set; } + public string Cabin { get; set; } + public ReservationStatus Status { get; set; } + } +}
\ No newline at end of file diff --git a/src/Data/DTOs/UpdatePasswordDto.cs b/src/Data/DTOs/UpdatePasswordDto.cs new file mode 100644 index 0000000..40ebd01 --- /dev/null +++ b/src/Data/DTOs/UpdatePasswordDto.cs @@ -0,0 +1,8 @@ +namespace IOL.Fagprove.Data.DTOs +{ + public class UpdatePasswordDto + { + public string Password { get; set; } + public string PasswordOnceMore { get; set; } + } +}
\ No newline at end of file diff --git a/src/Data/DTOs/UserDto.cs b/src/Data/DTOs/UserDto.cs new file mode 100644 index 0000000..26733d5 --- /dev/null +++ b/src/Data/DTOs/UserDto.cs @@ -0,0 +1,13 @@ +using System; +using IOL.Fagprove.Data.Enums; + +namespace IOL.Fagprove.Data.DTOs +{ + public class UserDto + { + public Guid Id { get; set; } + public string Name { get; set; } + public string Email { get; set; } + public UserRole Role { get; set; } + } +}
\ No newline at end of file diff --git a/src/Data/Enums/ReservationStatus.cs b/src/Data/Enums/ReservationStatus.cs new file mode 100644 index 0000000..a17e8d6 --- /dev/null +++ b/src/Data/Enums/ReservationStatus.cs @@ -0,0 +1,10 @@ +namespace IOL.Fagprove.Data.Enums +{ + public enum ReservationStatus + { + Pending = 0, // default + Granted = 1, + Rejected = 2, + Expired = 3 + } +}
\ No newline at end of file diff --git a/src/Data/Enums/UserRole.cs b/src/Data/Enums/UserRole.cs new file mode 100644 index 0000000..5ee70de --- /dev/null +++ b/src/Data/Enums/UserRole.cs @@ -0,0 +1,8 @@ +namespace IOL.Fagprove.Data.Enums +{ + public enum UserRole + { + Basic = 0, // default + Administrator = 1 + } +}
\ No newline at end of file diff --git a/src/Data/Models/CoreDataModel.cs b/src/Data/Models/CoreDataModel.cs new file mode 100644 index 0000000..a675ff1 --- /dev/null +++ b/src/Data/Models/CoreDataModel.cs @@ -0,0 +1,25 @@ +using System; + +namespace IOL.Fagprove.Data.Models +{ + public class CoreDataModel + { + public Guid Id { get; set; } + public DateTime? CreatedUtc { get; set; } + public Guid? CreatedBy { get; set; } + public DateTime? ModifiedUtc { get; set; } + public Guid? ModifiedBy { get; set; } + + public void SetIsUpdating(bool isUpdating = true) + { + if (isUpdating) + { + Id = Id; + CreatedUtc = CreatedUtc; + CreatedBy = CreatedBy; + ModifiedBy = ModifiedBy; + ModifiedUtc = ModifiedUtc; + } + } + } +} diff --git a/src/Data/Models/Reservation.cs b/src/Data/Models/Reservation.cs new file mode 100644 index 0000000..a70f732 --- /dev/null +++ b/src/Data/Models/Reservation.cs @@ -0,0 +1,15 @@ +using System; +using IOL.Fagprove.Data.Enums; + +namespace IOL.Fagprove.Data.Models +{ + public class Reservation : CoreDataModel + { + public Guid UserId { get; set; } + public Guid ReservationObjectId { get; set; } + public DateTime From { get; set; } + public DateTime To { get; set; } + public ReservationStatus Status { get; set; } + public string Extra { get; set; } + } +} diff --git a/src/Data/Models/ReservationObject.cs b/src/Data/Models/ReservationObject.cs new file mode 100644 index 0000000..61dcf84 --- /dev/null +++ b/src/Data/Models/ReservationObject.cs @@ -0,0 +1,13 @@ +using System; + +namespace IOL.Fagprove.Data.Models +{ + public class ReservationObject : CoreDataModel + { + public Guid CategoryId { get; set; } + public string Name { get; set; } + public int? Capacity { get; set; } + public string Price { get; set; } + public string Description { get; set; } + } +} diff --git a/src/Data/Models/User.cs b/src/Data/Models/User.cs new file mode 100644 index 0000000..3ff2878 --- /dev/null +++ b/src/Data/Models/User.cs @@ -0,0 +1,15 @@ +using IOL.Fagprove.Data.Enums; +using Microsoft.AspNetCore.Identity; + +namespace IOL.Fagprove.Data.Models +{ + public class User : CoreDataModel + { + public string Name { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public UserRole Role { get; set; } + + + } +}
\ No newline at end of file diff --git a/src/Data/Seed.cs b/src/Data/Seed.cs new file mode 100644 index 0000000..03bcdb2 --- /dev/null +++ b/src/Data/Seed.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using IOL.Fagprove.Data.Enums; +using IOL.Fagprove.Data.Models; +using IOL.Fagprove.Utilities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace IOL.Fagprove.Data +{ + public class Seed + { + public class SeedUsers : IEntityTypeConfiguration<User> + { + public void Configure(EntityTypeBuilder<User> builder) + { + builder.HasData(new List<User> + { + new User + { + Id = Guid.NewGuid(), + CreatedUtc = DateTime.UtcNow, + Email = "ivar@protektit.no", + Password = PasswordHasher.HashPassword("ivar123"), + Name = "Ivar Løvlie Administrator", + Role = UserRole.Administrator, + }, + new User + { + Id = Guid.NewGuid(), + CreatedUtc = DateTime.UtcNow, + Email = "ivarino@protektit.no", + Password = PasswordHasher.HashPassword("ivar123"), + Name = "Ivar Løvlie Standard", + Role = UserRole.Basic, + } + }); + } + } + } +}
\ No newline at end of file diff --git a/src/Data/StaticData.cs b/src/Data/StaticData.cs new file mode 100644 index 0000000..ab2a12a --- /dev/null +++ b/src/Data/StaticData.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; + +namespace IOL.Fagprove.Data +{ + public class ReservationObjectCategories + { + public Guid Id { get; set; } + public string Name { get; set; } + } + + public static class StaticData + { + public static List<ReservationObjectCategories> CabinFields => new List<ReservationObjectCategories> + { + new ReservationObjectCategories + { + Id = new Guid("77836174-c984-473d-a2b5-802e17fdba04"), + Name = "Hyttefelt 1" + }, + new ReservationObjectCategories + { + Id = new Guid("86ca4470-0036-446b-99a3-ed7e5131da81"), + Name = "Hyttefelt 2" + }, + new ReservationObjectCategories + { + Id = new Guid("25c7b7fe-1c61-47f0-a5f0-383351f00b1c"), + Name = "Hyttefelt 3" + }, + new ReservationObjectCategories + { + Id = new Guid("e3c19476-fde6-48af-952f-f2443f158f2c"), + Name = "Hyttefelt 4" + }, + new ReservationObjectCategories + { + Id = new Guid("546d7078-27ed-4aba-816e-e24d4212724c"), + Name = "Ikke spesifisert" + } + }; + } +}
\ No newline at end of file |
