by Anonymous » 17 Feb 2025, 08:57
Meine Dev -Umgebung ist ASP.NET Core 8.0 Rasierseiten mit EF Core und SQL Server in Visual Studio 2022. Code>. Ein Ereignis kann einen EventType .
Meine Modellklassen:
haben
Code: Select all
public class Event
{
public int Id { get; set; }
[DisplayName("Active")]
public required bool IsActive { get; set; }
public required string Title { get; set; }
public string? SubTitle { get; set; }
public required string Description { get; set; }
[DisplayName("Start Date")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateOnly StartDate { get; set; }
[DisplayName("End Date")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateOnly EndDate { get; set; }
[DisplayName("Start Time")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public required TimeOnly StartTime { get; set; }
[DisplayName("End Time")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public TimeOnly? EndTime { get; set; }
[DisplayName("Registration Ends")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public required TimeOnly RegistrationEndTime { get; set; }
[DisplayName("Buy In")]
[DisplayFormat(DataFormatString = "{0:C2}", ApplyFormatInEditMode = true)]
public decimal? BuyIn { get; set; }
[DisplayName("Chip Count")]
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
public decimal? ChipCount { get; set; }
// New property for Blinds, in minutes
[DisplayName("Blinds (Minutes)")]
public int? Blinds { get; set; }
// Custom property to display Blind duration with "minutes" suffix
[NotMapped]
public string BlindDisplay => $"{Blinds} minutes";
public string? Image { get; set; }
//Navigation Properties
[ForeignKey("Event")]
public required int EventTypeId { get; set; }
[DisplayName("Event Type")]
public required EventType EventType { get; set; }
}
public class EventType
{
public int Id { get; set; }
public required string Description { get; set; }
[StringLength(7, MinimumLength = 7, ErrorMessage = "Color must be exactly 7 characters long.")]
[RegularExpression("^#[a-f0-9]{6}$", ErrorMessage = "Color must start with '#' and be followed by 6 lowercase hexadecimal characters.")]
[DisplayName("Hex Color")]
public required string Color { get; set; }
}
Mein Code füllt eine Selektionsliste mit EventType (code> (
). Br /> Hier ist die OnPost < /code> -Methode: < /p>
Code: Select all
public async Task OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Events.Add(Events);
await _context.SaveChangesAsync();
TempData["success"] = "Event Type database entry successfully created.";
return RedirectToPage("./Index");
}
Hier ist der relevante Teil des Create.cSthml Formular
Meine Dev -Umgebung ist ASP.NET Core 8.0 Rasierseiten mit EF Core und SQL Server in Visual Studio 2022. Code>. Ein Ereignis kann einen EventType .
Meine Modellklassen:
haben[code]public class Event
{
public int Id { get; set; }
[DisplayName("Active")]
public required bool IsActive { get; set; }
public required string Title { get; set; }
public string? SubTitle { get; set; }
public required string Description { get; set; }
[DisplayName("Start Date")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateOnly StartDate { get; set; }
[DisplayName("End Date")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateOnly EndDate { get; set; }
[DisplayName("Start Time")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public required TimeOnly StartTime { get; set; }
[DisplayName("End Time")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public TimeOnly? EndTime { get; set; }
[DisplayName("Registration Ends")]
[DisplayFormat(DataFormatString = "{0:hh:mm tt}", ApplyFormatInEditMode = true)]
public required TimeOnly RegistrationEndTime { get; set; }
[DisplayName("Buy In")]
[DisplayFormat(DataFormatString = "{0:C2}", ApplyFormatInEditMode = true)]
public decimal? BuyIn { get; set; }
[DisplayName("Chip Count")]
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
public decimal? ChipCount { get; set; }
// New property for Blinds, in minutes
[DisplayName("Blinds (Minutes)")]
public int? Blinds { get; set; }
// Custom property to display Blind duration with "minutes" suffix
[NotMapped]
public string BlindDisplay => $"{Blinds} minutes";
public string? Image { get; set; }
//Navigation Properties
[ForeignKey("Event")]
public required int EventTypeId { get; set; }
[DisplayName("Event Type")]
public required EventType EventType { get; set; }
}
public class EventType
{
public int Id { get; set; }
public required string Description { get; set; }
[StringLength(7, MinimumLength = 7, ErrorMessage = "Color must be exactly 7 characters long.")]
[RegularExpression("^#[a-f0-9]{6}$", ErrorMessage = "Color must start with '#' and be followed by 6 lowercase hexadecimal characters.")]
[DisplayName("Hex Color")]
public required string Color { get; set; }
}
[/code]
Mein Code füllt eine Selektionsliste mit EventType (code> ([code]EventTypeSelectList[/code]). Br /> Hier ist die OnPost < /code> -Methode: < /p>
[code] public async Task OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Events.Add(Events);
await _context.SaveChangesAsync();
TempData["success"] = "Event Type database entry successfully created.";
return RedirectToPage("./Index");
}
[/code]
Hier ist der relevante Teil des Create.cSthml Formular
[code]
Submit
[/code]