From a395c2afe3042722a30ac5c64085ba2467c4dd2e Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Sat, 26 Mar 2022 22:25:46 +0200 Subject: [PATCH] feat: add database models and context --- TicketOffice/Data/TicketOfficeContext.cs | 26 +++++++++++++++++ TicketOffice/Models/City.cs | 27 ++++++++++++++++++ TicketOffice/Models/Route.cs | 23 +++++++++++++++ TicketOffice/Models/Ticket.cs | 15 ++++++++++ TicketOffice/Models/User.cs | 36 ++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 TicketOffice/Data/TicketOfficeContext.cs create mode 100644 TicketOffice/Models/City.cs create mode 100644 TicketOffice/Models/Route.cs create mode 100644 TicketOffice/Models/Ticket.cs create mode 100644 TicketOffice/Models/User.cs diff --git a/TicketOffice/Data/TicketOfficeContext.cs b/TicketOffice/Data/TicketOfficeContext.cs new file mode 100644 index 0000000..fec9b27 --- /dev/null +++ b/TicketOffice/Data/TicketOfficeContext.cs @@ -0,0 +1,26 @@ +#nullable disable +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using TicketOffice.Models; + +namespace TicketOffice.Data +{ + public class TicketOfficeContext : DbContext + { + public TicketOfficeContext (DbContextOptions options) + : base(options) + { + } + + public DbSet User { get; set; } + + public DbSet Route { get; set; } + + public DbSet City { get; set; } + + public DbSet Ticket { get; set; } + } +} diff --git a/TicketOffice/Models/City.cs b/TicketOffice/Models/City.cs new file mode 100644 index 0000000..92c9d67 --- /dev/null +++ b/TicketOffice/Models/City.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace TicketOffice.Models; + +public class City +{ + [Key] + public int Id { get; set; } + + [Required] + [StringLength(30, ErrorMessage = "City name can't be more than 30"), MinLength(2, ErrorMessage = "City name can't be less than 2")] + public string Name { get; set; } + + [Required] + [DataType(DataType.DateTime)] + public DateTime? ArrivalTime { get; set; } + + [Required] + [DataType(DataType.DateTime)] + public DateTime? DepartureTime { get; set; } + + [Required] + public decimal Distance { get; set; } + + public int RouteId { get; set; } + public Route Route { get; set; } +} \ No newline at end of file diff --git a/TicketOffice/Models/Route.cs b/TicketOffice/Models/Route.cs new file mode 100644 index 0000000..f2940b6 --- /dev/null +++ b/TicketOffice/Models/Route.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; + +namespace TicketOffice.Models; + +public class Route +{ + [Key] + public int Id { get; set; } + + [Required] + [StringLength(4, ErrorMessage = "Route number must be 4"), MinLength(4, ErrorMessage = "Route number must be 4")] + public string Number { get; set; } + + public ICollection? Cities { get; set; } + + [Required] + [Range(5, 50, ErrorMessage = "Capacity must be between 5 and 50")] + public int Capacity { get; set; } + + public int RemainingCapacity { get; set; } + + public ICollection? Tickets { get; set; } +} \ No newline at end of file diff --git a/TicketOffice/Models/Ticket.cs b/TicketOffice/Models/Ticket.cs new file mode 100644 index 0000000..e3f3147 --- /dev/null +++ b/TicketOffice/Models/Ticket.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace TicketOffice.Models; + +public class Ticket +{ + [Key] + public int Id { get; set; } + + public int UserId { get; set; } + public User User { get; set; } + + public int RouteId { get; set; } + public Route Route { get; set; } +} \ No newline at end of file diff --git a/TicketOffice/Models/User.cs b/TicketOffice/Models/User.cs new file mode 100644 index 0000000..27be0f3 --- /dev/null +++ b/TicketOffice/Models/User.cs @@ -0,0 +1,36 @@ +using System.ComponentModel.DataAnnotations; + +namespace TicketOffice.Models; + +public class User +{ + [Key] + public int Id { get; set; } + + [Required] + [StringLength(16, ErrorMessage = "First name lenght can't be more than 16"), MinLength(2, ErrorMessage = "First name can't be less than 2")] + public string FirstName { get; set; } + + [Required] + [StringLength(16, ErrorMessage = "Last name lenght can't be more than 16"), MinLength(2, ErrorMessage = "Last name can't be less than 2")] + public string LastName { get; set; } + + [Required] + [StringLength(16, ErrorMessage = "Patronymic lenght can't be more than 16"), MinLength(2, ErrorMessage = "Patronymic can't be less than 2")] + public string Patronymic { get; set; } + + [Required] + [EmailAddress] + public string Email { get; set; } + + [Required] + [DataType(DataType.Password)] + [StringLength(64, ErrorMessage = "Password lenght can't be more than 64"), MinLength(8, ErrorMessage = "Password lenght can't be less than 8")] + //[RegularExpression()] + public string Password { get; set; } + + public ICollection? Tickets { get; set; } + + [Required] + public bool IsManager { get; set; } = false; +} \ No newline at end of file