feat: add database models and context
This commit is contained in:
parent
d99e90bc03
commit
a395c2afe3
26
TicketOffice/Data/TicketOfficeContext.cs
Normal file
26
TicketOffice/Data/TicketOfficeContext.cs
Normal file
@ -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<TicketOfficeContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<TicketOffice.Models.User> User { get; set; }
|
||||
|
||||
public DbSet<TicketOffice.Models.Route> Route { get; set; }
|
||||
|
||||
public DbSet<TicketOffice.Models.City> City { get; set; }
|
||||
|
||||
public DbSet<TicketOffice.Models.Ticket> Ticket { get; set; }
|
||||
}
|
||||
}
|
27
TicketOffice/Models/City.cs
Normal file
27
TicketOffice/Models/City.cs
Normal file
@ -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; }
|
||||
}
|
23
TicketOffice/Models/Route.cs
Normal file
23
TicketOffice/Models/Route.cs
Normal file
@ -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<City>? 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<Ticket>? Tickets { get; set; }
|
||||
}
|
15
TicketOffice/Models/Ticket.cs
Normal file
15
TicketOffice/Models/Ticket.cs
Normal file
@ -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; }
|
||||
}
|
36
TicketOffice/Models/User.cs
Normal file
36
TicketOffice/Models/User.cs
Normal file
@ -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<Ticket>? Tickets { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool IsManager { get; set; } = false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user