From 5b8e95594695f4db0e09a165d15cbb8463f0f167 Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Sat, 18 Jun 2022 13:41:23 +0300 Subject: [PATCH] feat: add ticket cost; chore: suppress all nullable warnings --- ... 20220618101803_InitialCreate.Designer.cs} | 13 ++- ...ate.cs => 20220618101803_InitialCreate.cs} | 5 +- .../TicketOfficeContextModelSnapshot.cs | 9 ++ TicketOffice/Models/Route.cs | 12 +++ TicketOffice/Models/RouteCity.cs | 4 + TicketOffice/Models/SeedData.cs | 88 +++++++----------- TicketOffice/Models/Ticket.cs | 17 ++++ TicketOffice/Models/TicketCity.cs | 4 + TicketOffice/Pages/Auth/Login.cshtml.cs | 2 +- .../Pages/Management/Routes/Create.cshtml | 9 +- .../Pages/Management/Routes/Create.cshtml.cs | 20 ++-- .../Pages/Management/Routes/Edit.cshtml | 9 +- .../Pages/Management/Routes/Edit.cshtml.cs | 38 ++++---- .../Pages/Management/Routes/Index.cshtml.cs | 18 ++-- TicketOffice/Pages/Routes/Index.cshtml | 8 +- TicketOffice/Pages/Routes/Index.cshtml.cs | 8 +- TicketOffice/Services/PdfService.cs | 35 ++++++- .../Services/UserValidationService.cs | 2 - .../wwwroot/css/Management/Create.css | 8 +- .../wwwroot/db/TicketOffice-SQLite.db | Bin 53248 -> 53248 bytes 20 files changed, 200 insertions(+), 109 deletions(-) rename TicketOffice/Migrations/{20220609073909_Initial_Create.Designer.cs => 20220618101803_InitialCreate.Designer.cs} (94%) rename TicketOffice/Migrations/{20220609073909_Initial_Create.cs => 20220618101803_InitialCreate.cs} (95%) diff --git a/TicketOffice/Migrations/20220609073909_Initial_Create.Designer.cs b/TicketOffice/Migrations/20220618101803_InitialCreate.Designer.cs similarity index 94% rename from TicketOffice/Migrations/20220609073909_Initial_Create.Designer.cs rename to TicketOffice/Migrations/20220618101803_InitialCreate.Designer.cs index 30a26dd..4cb09cc 100644 --- a/TicketOffice/Migrations/20220609073909_Initial_Create.Designer.cs +++ b/TicketOffice/Migrations/20220618101803_InitialCreate.Designer.cs @@ -11,8 +11,8 @@ using TicketOffice.Data; namespace TicketOffice.Migrations { [DbContext(typeof(TicketOfficeContext))] - [Migration("20220609073909_Initial_Create")] - partial class Initial_Create + [Migration("20220618101803_InitialCreate")] + partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -45,6 +45,9 @@ namespace TicketOffice.Migrations b.Property("ArrivalTime") .HasColumnType("TEXT"); + b.Property("CostFromPreviousCity") + .HasColumnType("REAL"); + b.Property("DepartureTime") .HasColumnType("TEXT"); @@ -69,6 +72,9 @@ namespace TicketOffice.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("OderDate") + .HasColumnType("TEXT"); + b.Property("PassengerFirstName") .IsRequired() .HasColumnType("TEXT"); @@ -104,6 +110,9 @@ namespace TicketOffice.Migrations b.Property("ArrivalTime") .HasColumnType("TEXT"); + b.Property("CostFromPreviousCity") + .HasColumnType("REAL"); + b.Property("DepartureTime") .HasColumnType("TEXT"); diff --git a/TicketOffice/Migrations/20220609073909_Initial_Create.cs b/TicketOffice/Migrations/20220618101803_InitialCreate.cs similarity index 95% rename from TicketOffice/Migrations/20220609073909_Initial_Create.cs rename to TicketOffice/Migrations/20220618101803_InitialCreate.cs index 470892e..c91b97c 100644 --- a/TicketOffice/Migrations/20220609073909_Initial_Create.cs +++ b/TicketOffice/Migrations/20220618101803_InitialCreate.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace TicketOffice.Migrations { - public partial class Initial_Create : Migration + public partial class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -47,6 +47,7 @@ namespace TicketOffice.Migrations Name = table.Column(type: "TEXT", maxLength: 24, nullable: false), ArrivalTime = table.Column(type: "TEXT", nullable: true), DepartureTime = table.Column(type: "TEXT", nullable: true), + CostFromPreviousCity = table.Column(type: "REAL", nullable: true), RouteId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => @@ -69,6 +70,7 @@ namespace TicketOffice.Migrations PassengerFirstName = table.Column(type: "TEXT", nullable: false), PassengerLastName = table.Column(type: "TEXT", nullable: false), PassengerPlace = table.Column(type: "INTEGER", nullable: false), + OderDate = table.Column(type: "TEXT", nullable: false), UserId = table.Column(type: "INTEGER", nullable: false), RouteId = table.Column(type: "INTEGER", nullable: false) }, @@ -98,6 +100,7 @@ namespace TicketOffice.Migrations Name = table.Column(type: "TEXT", maxLength: 24, nullable: false), ArrivalTime = table.Column(type: "TEXT", nullable: true), DepartureTime = table.Column(type: "TEXT", nullable: true), + CostFromPreviousCity = table.Column(type: "REAL", nullable: true), TicketId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => diff --git a/TicketOffice/Migrations/TicketOfficeContextModelSnapshot.cs b/TicketOffice/Migrations/TicketOfficeContextModelSnapshot.cs index 570edbe..dd53635 100644 --- a/TicketOffice/Migrations/TicketOfficeContextModelSnapshot.cs +++ b/TicketOffice/Migrations/TicketOfficeContextModelSnapshot.cs @@ -43,6 +43,9 @@ namespace TicketOffice.Migrations b.Property("ArrivalTime") .HasColumnType("TEXT"); + b.Property("CostFromPreviousCity") + .HasColumnType("REAL"); + b.Property("DepartureTime") .HasColumnType("TEXT"); @@ -67,6 +70,9 @@ namespace TicketOffice.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("OderDate") + .HasColumnType("TEXT"); + b.Property("PassengerFirstName") .IsRequired() .HasColumnType("TEXT"); @@ -102,6 +108,9 @@ namespace TicketOffice.Migrations b.Property("ArrivalTime") .HasColumnType("TEXT"); + b.Property("CostFromPreviousCity") + .HasColumnType("REAL"); + b.Property("DepartureTime") .HasColumnType("TEXT"); diff --git a/TicketOffice/Models/Route.cs b/TicketOffice/Models/Route.cs index 15da58f..8949835 100644 --- a/TicketOffice/Models/Route.cs +++ b/TicketOffice/Models/Route.cs @@ -23,4 +23,16 @@ public class Route public List Cities { get; set; } = null!; public List? Tickets { get; set; } + + public double GetTotalCost() + { + double cost = 0; + + for (int i = 1; i < Cities.Count; i++) + { + cost += Cities.ToList()[i].CostFromPreviousCity ?? 0; + } + + return cost; + } } \ No newline at end of file diff --git a/TicketOffice/Models/RouteCity.cs b/TicketOffice/Models/RouteCity.cs index fa36312..49cce3f 100644 --- a/TicketOffice/Models/RouteCity.cs +++ b/TicketOffice/Models/RouteCity.cs @@ -22,6 +22,10 @@ public class RouteCity [DataType(DataType.Date)] public DateTime? DepartureTime { get; set; } + [Display(Name = "Ціна подорожі з попереднього міста")] + [DataType(DataType.Currency)] + public double? CostFromPreviousCity { get; set; } + [ForeignKey("Route")] public int RouteId { get; set; } public Route Route { get; set; } = null!; diff --git a/TicketOffice/Models/SeedData.cs b/TicketOffice/Models/SeedData.cs index 83360ca..93b37f6 100644 --- a/TicketOffice/Models/SeedData.cs +++ b/TicketOffice/Models/SeedData.cs @@ -51,21 +51,19 @@ public class SeedData new RouteCity { Name = "Сватове", - ArrivalTime = null, - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 6, 30, - 0) + 0), + CostFromPreviousCity = null }, new RouteCity { Name = "Красноріченське", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -73,19 +71,18 @@ public class SeedData 7, 10, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 7, 20, - 0) + 0), + CostFromPreviousCity = 30 }, new RouteCity { Name = "Кремінна", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -93,19 +90,18 @@ public class SeedData 7, 50, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 0, - 0) + 0), + CostFromPreviousCity = 30 }, new RouteCity { Name = "Рубіжне", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -113,19 +109,18 @@ public class SeedData 8, 30, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 40, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Сєвєродонецьк", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -133,19 +128,18 @@ public class SeedData 9, 10, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9, 20, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Лисичанськ", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -153,7 +147,6 @@ public class SeedData 9, 50, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -161,11 +154,11 @@ public class SeedData 12, 0, 0), + CostFromPreviousCity = 20 }, new RouteCity { Name = "Сєвєродонецьк", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -173,19 +166,18 @@ public class SeedData 12, 30, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 12, 40, - 0) + 0), + CostFromPreviousCity = 20 }, new RouteCity { Name = "Рубіжне", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -193,19 +185,18 @@ public class SeedData 13, 10, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 13, 20, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Кремінна", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -213,19 +204,18 @@ public class SeedData 13, 50, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 14, 0, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Красноріченське", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -233,19 +223,18 @@ public class SeedData 14, 30, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 14, 40, - 0) + 0), + CostFromPreviousCity = 30 }, new RouteCity { Name = "Сватове", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -253,8 +242,8 @@ public class SeedData 15, 20, 0), - - DepartureTime = null + DepartureTime = null, + CostFromPreviousCity = 30 } } }, @@ -267,21 +256,19 @@ public class SeedData new RouteCity { Name = "Кремінна", - ArrivalTime = null, - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 7, 0, - 0) + 0), + CostFromPreviousCity = null }, new RouteCity { Name = "Рубіжне", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -289,19 +276,18 @@ public class SeedData 7, 30, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 7, 40, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Сєвєродонецьк", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -309,19 +295,18 @@ public class SeedData 8, 10, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 20, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Станиця Луганська", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -329,19 +314,18 @@ public class SeedData 9, 20, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 11, 20, - 0) + 0), + CostFromPreviousCity = 40 }, new RouteCity { Name = "Сєвєродонецьк", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -349,19 +333,18 @@ public class SeedData 12, 20, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 12, 30, - 0) + 0), + CostFromPreviousCity = 40 }, new RouteCity { Name = "Рубіжне", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -369,19 +352,18 @@ public class SeedData 13, 0, 0), - DepartureTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 13, 10, - 0) + 0), + CostFromPreviousCity = 15 }, new RouteCity { Name = "Кремінна", - ArrivalTime = new DateTime( DateTime.Today.Year, DateTime.Today.Month, @@ -389,8 +371,8 @@ public class SeedData 13, 40, 0), - - DepartureTime = null + DepartureTime = null, + CostFromPreviousCity = 15 } } } diff --git a/TicketOffice/Models/Ticket.cs b/TicketOffice/Models/Ticket.cs index 946cb69..6278828 100644 --- a/TicketOffice/Models/Ticket.cs +++ b/TicketOffice/Models/Ticket.cs @@ -19,6 +19,11 @@ public class Ticket [Required(ErrorMessage = "Поле має бути заповненим")] [Display(Name = "Номер місця пасажира")] public int PassengerPlace { get; set; } + + [Required] + [Display(Name = "Дата придбання квитка")] + public DateTime OderDate { get; set; } + [Required] public ICollection Cities { get; set; } = null!; @@ -30,4 +35,16 @@ public class Ticket [ForeignKey("Route")] public int RouteId { get; set; } public Route Route { get; set; } = null!; + + public double GetTotalCost() + { + double cost = 0; + + for (int i = 1; i < Cities.Count; i++) + { + cost += Cities.ToList()[i].CostFromPreviousCity ?? 0; + } + + return cost; + } } \ No newline at end of file diff --git a/TicketOffice/Models/TicketCity.cs b/TicketOffice/Models/TicketCity.cs index 4b5b4a8..d50f59a 100644 --- a/TicketOffice/Models/TicketCity.cs +++ b/TicketOffice/Models/TicketCity.cs @@ -22,6 +22,10 @@ public class TicketCity [DataType(DataType.Date)] public DateTime? DepartureTime { get; set; } + [Display(Name = "Ціна подорожі з попереднього міста")] + [DataType(DataType.Currency)] + public double? CostFromPreviousCity { get; set; } + [ForeignKey("Ticket")] public int TicketId { get; set; } public Ticket Ticket { get; set; } = null!; diff --git a/TicketOffice/Pages/Auth/Login.cshtml.cs b/TicketOffice/Pages/Auth/Login.cshtml.cs index 55c5de9..2628238 100644 --- a/TicketOffice/Pages/Auth/Login.cshtml.cs +++ b/TicketOffice/Pages/Auth/Login.cshtml.cs @@ -51,7 +51,7 @@ public class LoginModel : PageModel .FirstOrDefault(u => u.Email == User!.Email); HttpContext.Session.SetInt32("UserId", user!.Id); - HttpContext.Session.SetInt32("IsManager", user!.IsManager ? 1 : 0); + HttpContext.Session.SetInt32("IsManager", user.IsManager ? 1 : 0); return RedirectToPage("/Auth/Account"); } diff --git a/TicketOffice/Pages/Management/Routes/Create.cshtml b/TicketOffice/Pages/Management/Routes/Create.cshtml index 4780ea1..338ad45 100644 --- a/TicketOffice/Pages/Management/Routes/Create.cshtml +++ b/TicketOffice/Pages/Management/Routes/Create.cshtml @@ -37,14 +37,19 @@
- +
@Model.ArrivalTimeValidationError[i]
- +
@Model.DepartureTimeValidationError[i]
+ +
+ + @*
@Model.DepartureTimeValidationError[i]
*@ +
} diff --git a/TicketOffice/Pages/Management/Routes/Create.cshtml.cs b/TicketOffice/Pages/Management/Routes/Create.cshtml.cs index 7351c63..0d97c98 100644 --- a/TicketOffice/Pages/Management/Routes/Create.cshtml.cs +++ b/TicketOffice/Pages/Management/Routes/Create.cshtml.cs @@ -17,15 +17,15 @@ public class CreateModel : PageModel public string CapacityValidationError = null!; // Array of error massages displaying when route name validation failed. - public string[] NameValidationError; + public string[] NameValidationError = null!; // Array of error massages displaying when cities // departure time validation failed. - public string[] DepartureTimeValidationError; + public string[] DepartureTimeValidationError = null!; // Array of error massages displaying when cities // arrival time validation failed. - public string[] ArrivalTimeValidationError; + public string[] ArrivalTimeValidationError = null!; private readonly TicketOfficeContext context; private readonly UserValidationService validationService; @@ -39,12 +39,12 @@ public class CreateModel : PageModel // Object representing that will be created. [BindProperty] - public Route Route { get; set; } + public Route Route { get; set; } = null!; // Object holding cities' arrival/departure dates. [BindProperty] - public DateString[] TimeStrings { get; set; } - + public DateString[] TimeStrings { get; set; } = null!; + // Amount of cities to be added to the route [BindProperty] public int? CitiesCount { get; set; } @@ -109,9 +109,9 @@ public class CreateModel : PageModel try { Route.Cities[i].DepartureTime = - ConvertStringToDate(TimeStrings[i].DepartureDate); + ConvertStringToDate(TimeStrings[i].DepartureDate!); } - catch(Exception e) + catch(Exception) { if (Route.Cities.Count > 2) { @@ -126,9 +126,9 @@ public class CreateModel : PageModel try { Route.Cities[i].ArrivalTime = - ConvertStringToDate(TimeStrings[i].ArrivalDate); + ConvertStringToDate(TimeStrings[i].ArrivalDate!); } - catch(Exception e) + catch(Exception) { if (Route.Cities.Count > 2) { diff --git a/TicketOffice/Pages/Management/Routes/Edit.cshtml b/TicketOffice/Pages/Management/Routes/Edit.cshtml index 01c7498..741a5bc 100644 --- a/TicketOffice/Pages/Management/Routes/Edit.cshtml +++ b/TicketOffice/Pages/Management/Routes/Edit.cshtml @@ -36,15 +36,20 @@
- +
@Model.ArrivalTimeValidationError[i]
- +
@Model.DepartureTimeValidationError[i]
+
+ + @*
@Model.DepartureTimeValidationError[i]
*@ +
+ } diff --git a/TicketOffice/Pages/Management/Routes/Edit.cshtml.cs b/TicketOffice/Pages/Management/Routes/Edit.cshtml.cs index 79accd6..9a03650 100644 --- a/TicketOffice/Pages/Management/Routes/Edit.cshtml.cs +++ b/TicketOffice/Pages/Management/Routes/Edit.cshtml.cs @@ -18,15 +18,15 @@ public class EditModel : PageModel public string CapacityValidationError = null!; // Array of error massages displaying when route name validation failed. - public string[] NameValidationError; + public string[] NameValidationError = null!; // Array of error massages displaying when cities // departure time validation failed. - public string[] DepartureTimeValidationError; + public string[] DepartureTimeValidationError = null!; // Array of error massages displaying when cities // arrival time validation failed. - public string[] ArrivalTimeValidationError; + public string[] ArrivalTimeValidationError = null!; private readonly TicketOfficeContext context; private readonly UserValidationService validationService; @@ -40,15 +40,15 @@ public class EditModel : PageModel // Object representing that will be created. [BindProperty] - public Route Route { get; set; } + public Route? Route { get; set; } // Object holding cities' arrival/departure dates. [BindProperty] - public DateString[] TimeStrings { get; set; } + public DateString[] TimeStrings { get; set; } = null!; // Holds cities' ids between loading and saving [BindProperty] - public int[] CityIds { get; set; } + public int[] CityIds { get; set; } = null!; // Called when GET request is sent to the page. // Retrieves route. @@ -93,7 +93,7 @@ public class EditModel : PageModel InitializeArrays(); InsertDatesIntoCities(); LoadCityIds(); - Route.Id = (int) id; + Route!.Id = (int) id; if (!ValidateInput()) { @@ -133,15 +133,15 @@ public class EditModel : PageModel private void InsertDatesIntoCities() { - for (int i = 0; i < Route.Cities.Count; i++) + for (int i = 0; i < Route!.Cities.Count; i++) { try { Route.Cities[i].DepartureTime = - ConvertStringToDate(TimeStrings[i].DepartureDate); + ConvertStringToDate(TimeStrings[i].DepartureDate!); } - catch(Exception e) + catch(Exception) { if (Route.Cities.Count > 2) { @@ -155,9 +155,9 @@ public class EditModel : PageModel try { Route.Cities[i].ArrivalTime = - ConvertStringToDate(TimeStrings[i].ArrivalDate); + ConvertStringToDate(TimeStrings[i].ArrivalDate!); } - catch(Exception e) + catch(Exception) { if (Route.Cities.Count > 2) { @@ -195,17 +195,17 @@ public class EditModel : PageModel private void InsertDatesIntoStrings() { - for (int i = 0; i < Route.Cities.Count; i++) + for (int i = 0; i < Route!.Cities.Count; i++) { if (Route.Cities[i].DepartureTime != null) { - TimeStrings[i].DepartureDate = Route.Cities[i].DepartureTime + TimeStrings[i].DepartureDate = Route.Cities[i].DepartureTime! .Value.ToString("dd.MM.yyyy, hh:mm"); } if (Route.Cities[i].ArrivalTime != null) { - TimeStrings[i].ArrivalDate = Route.Cities[i].ArrivalTime + TimeStrings[i].ArrivalDate = Route.Cities[i].ArrivalTime! .Value.ToString("dd.MM.yyyy, hh:mm"); } } @@ -215,7 +215,7 @@ public class EditModel : PageModel // an idea. It should be removed. private void SaveCityIds() { - CityIds = new int[Route.Cities.Count]; + CityIds = new int[Route!.Cities.Count]; for (int i = 0; i < Route.Cities.Count; i++) { @@ -227,13 +227,13 @@ public class EditModel : PageModel { for (int i = 0; i < CityIds.Length; i++) { - Route.Cities[i].Id = CityIds[i]; + Route!.Cities[i].Id = CityIds[i]; } } private bool ValidateInput() { - bool isValidNumber = ValidateNumber(Route.Number, out NumberValidationError); + bool isValidNumber = ValidateNumber(Route!.Number, out NumberValidationError); bool isValidCapacity = ValidateCapacity(Route.Capacity, out CapacityValidationError); @@ -352,7 +352,7 @@ public class EditModel : PageModel private void InitializeArrays() { - NameValidationError = InitializeArray(Route.Cities.Count, ""); + NameValidationError = InitializeArray(Route!.Cities.Count, ""); DepartureTimeValidationError = InitializeArray(Route.Cities.Count, ""); ArrivalTimeValidationError = InitializeArray(Route.Cities.Count, ""); } diff --git a/TicketOffice/Pages/Management/Routes/Index.cshtml.cs b/TicketOffice/Pages/Management/Routes/Index.cshtml.cs index 3be773a..3cbae1b 100644 --- a/TicketOffice/Pages/Management/Routes/Index.cshtml.cs +++ b/TicketOffice/Pages/Management/Routes/Index.cshtml.cs @@ -37,11 +37,7 @@ namespace TicketOffice.Pages.Management.Routes // Search condition: departure date. [BindProperty(SupportsGet = true)] public DateTime? Date { get; set; } - - // Will be set when user confirm route deletion. - [BindProperty(SupportsGet = true)] - public int DeleteRouteId { get; set; } - + // Called when GET request is sent to the page. // Retrieves routes based on search conditions. public ActionResult OnGet() @@ -61,11 +57,11 @@ namespace TicketOffice.Pages.Management.Routes } // Called when user confirms route deletion. - public ActionResult OnGetDeleteRoute() + public ActionResult OnGetDeleteRoute(int deleteRouteId) { OnGet(); - Route? deleteRoute = context.Route.Find(DeleteRouteId); + Route? deleteRoute = context.Route.Find(deleteRouteId); if (deleteRoute != null) { @@ -92,7 +88,7 @@ namespace TicketOffice.Pages.Management.Routes return; } - Routes.RemoveAll(r => r.Number != Number); + Routes!.RemoveAll(r => r.Number != Number); } private void FilterRoutesByFrom() @@ -102,7 +98,7 @@ namespace TicketOffice.Pages.Management.Routes return; } - Routes.RemoveAll(r => r.Cities.All(c => c.Name != From)); + Routes!.RemoveAll(r => r.Cities.All(c => c.Name != From)); } private void FilterRoutesByTo() @@ -112,7 +108,7 @@ namespace TicketOffice.Pages.Management.Routes return; } - Routes.RemoveAll(r => r.Cities.All(c => c.Name != To)); + Routes!.RemoveAll(r => r.Cities.All(c => c.Name != To)); } private void FilterRoutesByDate() @@ -122,7 +118,7 @@ namespace TicketOffice.Pages.Management.Routes return; } - Routes.RemoveAll(r => + Routes!.RemoveAll(r => r.Cities.All(c => c.DepartureTime?.Date != Date?.Date && c.ArrivalTime?.Date != Date?.Date)); diff --git a/TicketOffice/Pages/Routes/Index.cshtml b/TicketOffice/Pages/Routes/Index.cshtml index 9de965d..5407e20 100644 --- a/TicketOffice/Pages/Routes/Index.cshtml +++ b/TicketOffice/Pages/Routes/Index.cshtml @@ -119,6 +119,9 @@ Вільніих місць + + Ціна + Дії @@ -166,6 +169,9 @@ @Model.GetRemainingCapacity(route) + + @route.GetTotalCost() + Обрати @@ -371,7 +377,7 @@ Закрити @if (HttpContext.Session.GetString("UserId") != null) { - + } else { diff --git a/TicketOffice/Pages/Routes/Index.cshtml.cs b/TicketOffice/Pages/Routes/Index.cshtml.cs index b25ecdf..33eb37e 100644 --- a/TicketOffice/Pages/Routes/Index.cshtml.cs +++ b/TicketOffice/Pages/Routes/Index.cshtml.cs @@ -75,9 +75,10 @@ public class IndexModel : PageModel return OnGet(); } - CopyCitiesToTicket(); + CopyDataToTicket(); RevertChangesToRouteCities(); + Ticket.OderDate = DateTime.Now; context.Ticket.Add(Ticket); context.SaveChanges(); @@ -387,7 +388,7 @@ public class IndexModel : PageModel return true; } - private void CopyCitiesToTicket() + private void CopyDataToTicket() { List routeCities = Routes!.Find(r => r.Id == Ticket!.RouteId)!.Cities.ToList(); @@ -400,7 +401,8 @@ public class IndexModel : PageModel { Name = city.Name, DepartureTime = city.DepartureTime, - ArrivalTime = city.ArrivalTime + ArrivalTime = city.ArrivalTime, + CostFromPreviousCity = city.CostFromPreviousCity }); } } diff --git a/TicketOffice/Services/PdfService.cs b/TicketOffice/Services/PdfService.cs index 2e508ba..1c4d058 100644 --- a/TicketOffice/Services/PdfService.cs +++ b/TicketOffice/Services/PdfService.cs @@ -45,7 +45,7 @@ public class PdfService firstParagraphPoint, roboto); page.AddText( - $"№ {ticket.RouteId}", + $"№ {ticket.Route.Number}", 14, firstParagraphPoint.Translate(250, 0), roboto); @@ -90,6 +90,39 @@ public class PdfService firstParagraphPoint.Translate(250, 3 * -lineHeight), roboto); + page.AddText( + "Ціна:", + 14, + firstParagraphPoint.Translate(0, 4 * -lineHeight), + roboto); + page.AddText( + $"{ticket.GetTotalCost()}", + 14, + firstParagraphPoint.Translate(250, 4 * -lineHeight), + roboto); + + page.AddText( + "Дата придбання квитка:", + 14, + firstParagraphPoint.Translate(0, 6 * -lineHeight), + roboto); + page.AddText( + $"{ticket.OderDate.ToString("dd.MM.yyyy, HH:mm:ss")}", + 14, + firstParagraphPoint.Translate(250, 6 * -lineHeight), + roboto); + + page.AddText( + "Дата генерації квитка:", + 14, + firstParagraphPoint.Translate(0, 7 * -lineHeight), + roboto); + page.AddText( + $"{DateTime.Now.ToString("dd.MM.yyyy, HH:mm:ss")}", + 14, + firstParagraphPoint.Translate(250, 7 * -lineHeight), + roboto); + byte[] document = builder.Build(); //Saving the PDF to the MemoryStream diff --git a/TicketOffice/Services/UserValidationService.cs b/TicketOffice/Services/UserValidationService.cs index ef99878..2e816c0 100644 --- a/TicketOffice/Services/UserValidationService.cs +++ b/TicketOffice/Services/UserValidationService.cs @@ -1,5 +1,3 @@ -using Microsoft.AspNetCore.Mvc; - namespace TicketOffice.Services; public class UserValidationService diff --git a/TicketOffice/wwwroot/css/Management/Create.css b/TicketOffice/wwwroot/css/Management/Create.css index b1fa5fb..779fcff 100644 --- a/TicketOffice/wwwroot/css/Management/Create.css +++ b/TicketOffice/wwwroot/css/Management/Create.css @@ -41,7 +41,13 @@ div.city-name { } div.city-date { - width: 17.5rem; + width: 15rem; + margin: 0 auto; + font-size: 0.9rem; +} + +div.city-cost { + width: 7.5rem; margin: 0 auto; font-size: 1rem; } diff --git a/TicketOffice/wwwroot/db/TicketOffice-SQLite.db b/TicketOffice/wwwroot/db/TicketOffice-SQLite.db index 3751dfe6e14e651f513c02b251a5341e2cf3155e..eac1c917066e907c3ce23b13a6c9a818af55a262 100644 GIT binary patch liter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