feat: add ticket cost; chore: suppress all nullable warnings

This commit is contained in:
cuqmbr 2022-06-18 13:41:23 +03:00
parent b9f8fe4521
commit 5b8e955946
20 changed files with 200 additions and 109 deletions

View File

@ -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<DateTime?>("ArrivalTime")
.HasColumnType("TEXT");
b.Property<double?>("CostFromPreviousCity")
.HasColumnType("REAL");
b.Property<DateTime?>("DepartureTime")
.HasColumnType("TEXT");
@ -69,6 +72,9 @@ namespace TicketOffice.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("OderDate")
.HasColumnType("TEXT");
b.Property<string>("PassengerFirstName")
.IsRequired()
.HasColumnType("TEXT");
@ -104,6 +110,9 @@ namespace TicketOffice.Migrations
b.Property<DateTime?>("ArrivalTime")
.HasColumnType("TEXT");
b.Property<double?>("CostFromPreviousCity")
.HasColumnType("REAL");
b.Property<DateTime?>("DepartureTime")
.HasColumnType("TEXT");

View File

@ -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<string>(type: "TEXT", maxLength: 24, nullable: false),
ArrivalTime = table.Column<DateTime>(type: "TEXT", nullable: true),
DepartureTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CostFromPreviousCity = table.Column<double>(type: "REAL", nullable: true),
RouteId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
@ -69,6 +70,7 @@ namespace TicketOffice.Migrations
PassengerFirstName = table.Column<string>(type: "TEXT", nullable: false),
PassengerLastName = table.Column<string>(type: "TEXT", nullable: false),
PassengerPlace = table.Column<int>(type: "INTEGER", nullable: false),
OderDate = table.Column<DateTime>(type: "TEXT", nullable: false),
UserId = table.Column<int>(type: "INTEGER", nullable: false),
RouteId = table.Column<int>(type: "INTEGER", nullable: false)
},
@ -98,6 +100,7 @@ namespace TicketOffice.Migrations
Name = table.Column<string>(type: "TEXT", maxLength: 24, nullable: false),
ArrivalTime = table.Column<DateTime>(type: "TEXT", nullable: true),
DepartureTime = table.Column<DateTime>(type: "TEXT", nullable: true),
CostFromPreviousCity = table.Column<double>(type: "REAL", nullable: true),
TicketId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>

View File

@ -43,6 +43,9 @@ namespace TicketOffice.Migrations
b.Property<DateTime?>("ArrivalTime")
.HasColumnType("TEXT");
b.Property<double?>("CostFromPreviousCity")
.HasColumnType("REAL");
b.Property<DateTime?>("DepartureTime")
.HasColumnType("TEXT");
@ -67,6 +70,9 @@ namespace TicketOffice.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("OderDate")
.HasColumnType("TEXT");
b.Property<string>("PassengerFirstName")
.IsRequired()
.HasColumnType("TEXT");
@ -102,6 +108,9 @@ namespace TicketOffice.Migrations
b.Property<DateTime?>("ArrivalTime")
.HasColumnType("TEXT");
b.Property<double?>("CostFromPreviousCity")
.HasColumnType("REAL");
b.Property<DateTime?>("DepartureTime")
.HasColumnType("TEXT");

View File

@ -23,4 +23,16 @@ public class Route
public List<RouteCity> Cities { get; set; } = null!;
public List<Ticket>? 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;
}
}

View File

@ -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!;

View File

@ -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
}
}
}

View File

@ -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<TicketCity> 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;
}
}

View File

@ -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!;

View File

@ -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");
}

View File

@ -37,14 +37,19 @@
</div>
<div class="city-date">
<input class="field-city" type="text" placeholder="Дата й час прибуття" autocomplete="off" asp-for="TimeStrings[i].ArrivalDate">
<input class="field-city" type="text" placeholder="Дата прибуття" autocomplete="off" asp-for="TimeStrings[i].ArrivalDate">
<div class="validation-error"><span></span>@Model.ArrivalTimeValidationError[i]</div>
</div>
<div class="city-date">
<input class="field-city" type="text" placeholder="Дата й час відправлення" autocomplete="off" asp-for="TimeStrings[i].DepartureDate">
<input class="field-city" type="text" placeholder="Дата відправлення" autocomplete="off" asp-for="TimeStrings[i].DepartureDate">
<div class="validation-error"><span>@Model.DepartureTimeValidationError[i]</span></div>
</div>
<div class="city-cost">
<input class="field-city" type="number" placeholder="Ціна" autocomplete="off" value="" min="0" asp-for="Route.Cities[i].CostFromPreviousCity">
@* <div class="validation-error"><span>@Model.DepartureTimeValidationError[i]</span></div> *@
</div>
</div>
}

View File

@ -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)
{

View File

@ -36,15 +36,20 @@
</div>
<div class="city-date">
<input class="field-city" type="text" placeholder="Дата й час прибуття" autocomplete="off" asp-for="TimeStrings[i].ArrivalDate">
<input class="field-city" type="text" placeholder="Дата прибуття" autocomplete="off" asp-for="TimeStrings[i].ArrivalDate">
<div class="validation-error"><span></span>@Model.ArrivalTimeValidationError[i]</div>
</div>
<div class="city-date">
<input class="field-city" type="text" placeholder="Дата й час відправлення" autocomplete="off" asp-for="TimeStrings[i].DepartureDate">
<input class="field-city" type="text" placeholder="Дата відправлення" autocomplete="off" asp-for="TimeStrings[i].DepartureDate">
<div class="validation-error"><span>@Model.DepartureTimeValidationError[i]</span></div>
</div>
<div class="city-cost">
<input class="field-city" type="number" placeholder="Ціна" autocomplete="off" min="0" asp-for="Route.Cities[i].CostFromPreviousCity">
@* <div class="validation-error"><span>@Model.DepartureTimeValidationError[i]</span></div> *@
</div>
<input type="number" hidden value="@Model.Route.Cities[i].Id" asp-for="CityIds[i]">
</div>
}

View File

@ -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<string>(Route.Cities.Count, "");
NameValidationError = InitializeArray<string>(Route!.Cities.Count, "");
DepartureTimeValidationError = InitializeArray<string>(Route.Cities.Count, "");
ArrivalTimeValidationError = InitializeArray<string>(Route.Cities.Count, "");
}

View File

@ -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));

View File

@ -119,6 +119,9 @@
<th>
Вільніих місць
</th>
<th>
Ціна
</th>
<th>
Дії
</th>
@ -166,6 +169,9 @@
<td class="capacity">
@Model.GetRemainingCapacity(route)
</td>
<td class="capacity">
@route.GetTotalCost()
</td>
<td class="action">
<a class="link-btn-choose" onclick="document.getElementById('popup-ticket-@route.Id').style.display = 'inherit'">Обрати</a>
</td>
@ -371,7 +377,7 @@
<a class="popup-footer-link-button-ticket-order" onclick="document.getElementById('popup-ticket-@route.Id').style.display = 'none'">Закрити</a>
@if (HttpContext.Session.GetString("UserId") != null)
{
<input class="popup-footer-button-ticket-order" type="submit" form="ticket-form-@route.Id" value="Купити">
<input class="popup-footer-button-ticket-order" type="submit" form="ticket-form-@route.Id" value="Купити (@route.GetTotalCost())">
}
else
{

View File

@ -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<RouteCity> 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
});
}
}

View File

@ -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

View File

@ -1,5 +1,3 @@
using Microsoft.AspNetCore.Mvc;
namespace TicketOffice.Services;
public class UserValidationService

View File

@ -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;
}