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 3751dfe..eac1c91 100644 Binary files a/TicketOffice/wwwroot/db/TicketOffice-SQLite.db and b/TicketOffice/wwwroot/db/TicketOffice-SQLite.db differ