diff --git a/Areas/MMS/Controllers/MarineController.cs b/Areas/MMS/Controllers/MarineController.cs index a2fcafc..e009836 100644 --- a/Areas/MMS/Controllers/MarineController.cs +++ b/Areas/MMS/Controllers/MarineController.cs @@ -6,29 +6,27 @@ using PSTW_CentralSystem.Models; using PSTW_CentralSystem.Areas.MMS; using System.Linq; using QuestPDF.Fluent; +using PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator; namespace PSTW_CentralSystem.Areas.MMS.Controllers { [Area("MMS")] - //[Authorize(Policy = "RoleModulePolicy")] - public class MarineController : Controller + public class MarineController(MMSSystemContext context) : Controller { - private readonly MMSSystemContext _context; - public MarineController(MMSSystemContext context) - { - _context = context; - } + private readonly MMSSystemContext _context = context; + public IActionResult Index() { return View(); // This will look for Index.cshtml in Areas/MMS/Views/Marine } + public IActionResult TarBallForm() { var marineTarballs = _context.MarineTarballs .Select(t => new { - t.Id, //Include Id property + t.Id, // Include Id property Date = t.DateSample, Station = t.StationID }) @@ -46,26 +44,34 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers public IActionResult GenerateReport(int id) { + Console.WriteLine($"Requested ID in GenerateReport: {id}"); // Log the ID + try { - // Retrieve the specific record based on the id - var tarballData = _context.MarineTarballs - .Where(t => t.Id == id) - .Select(t => new - { - t.StationID, - t.DateSample - }) - .FirstOrDefault(); + // Retrieve the specific record based on the id, including the related StateID + var tarballData = (from marine in _context.MarineTarballs + join station in _context.TarballStations + on marine.StationID equals station.StationID + join state in _context.States + on station.StateID equals state.StateID + where marine.Id == id + select new + { + marine.StationID, + marine.DateSample, + state.StateName // Get the full state name + }).FirstOrDefault(); if (tarballData == null) { return NotFound("The specified record was not found."); } + Console.WriteLine($"Found Record: StationID = {tarballData.StationID}, StateName = {tarballData.StateName}"); + // Generate the PDF - var document = new TarBallPDF(); // Customize the report if needed - var pdf = document.GeneratePdf(); + var pdfdocument = new TarBallPDF(tarballData.StationID, tarballData.StateName); // Pass StateID to the PDF generator + var pdf = pdfdocument.GeneratePdf(); // Construct the filename var formattedDate = tarballData.DateSample.ToString("ddMMyyyy"); @@ -83,28 +89,39 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers public IActionResult ViewPDF(int id) { + Console.WriteLine("testing"); //TESTING DEBUGGING + Console.WriteLine($"Requested ID in ViewReport: {id}"); // Log the ID + try { - // Retrieve the specific record based on the id - var tarballData = _context.MarineTarballs - .Where(t => t.Id == id) - .Select(t => new - { - t.StationID, - t.DateSample - }) - .FirstOrDefault(); + // Retrieve the specific record based on the id, including the related StateID + var tarballData = (from marine in _context.MarineTarballs + join station in _context.TarballStations + on marine.StationID equals station.StationID into StationGroup + from station in StationGroup.DefaultIfEmpty() //Handle missing + join state in _context.States + on station.StateID equals state.StateID + where marine.Id == id + select new + { + marine.StationID, + marine.DateSample, + StationExists = station != null, + state.StateName // Get the full state name + }).FirstOrDefault(); if (tarballData == null) { return NotFound("The specified record was not found."); } + Console.WriteLine($"Found Record: StationID = {tarballData.StationID}, StateName = {tarballData.StateName}"); + // Generate the PDF - var document = new TarBallPDF(); // Customize the PDF if needed + var document = new TarBallPDF(tarballData.StationID, tarballData.StateName); // Pass StateID to the PDF generator var pdf = document.GeneratePdf(); - //For filename + // Construct the filename var formattedDate = tarballData.DateSample.ToString("ddMMyyyy"); var fileName = $"TbReport_{tarballData.StationID}_{formattedDate}.pdf"; @@ -117,6 +134,5 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while viewing the PDF. " + ex.Message); } } - } } diff --git a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs index e79fa8f..6ef8747 100644 --- a/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs +++ b/Areas/MMS/Models/PDFGenerator/TarBallPDF.cs @@ -1,277 +1,275 @@ using QuestPDF.Fluent; using QuestPDF.Infrastructure; using QuestPDF.Helpers; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -public class TarBallPDF : IDocument +namespace PSTW_CentralSystem.Areas.MMS.Models.PDFGenerator { - public DocumentMetadata GetMetadata() => new DocumentMetadata + public class TarBallPDF : IDocument { - Title = "TarBall Sampling Form", - Author = "PAKAR SCIENO TW Integrated Environmental Solutions", - Subject = "Environmental Survey and Observations" - }; + private readonly string _stationId; + private readonly string _stateName; - public void Compose(IDocumentContainer container) - { - container.Page(page => + // Constructor + public TarBallPDF(string stationId, string stateName) { - // Page Setup - page.Size(PageSizes.A4); - page.Margin(1.1f, Unit.Centimetre); - page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(10)); + _stationId = stationId; + _stateName = stateName; + } - // Header Section - page.Header().Row(row => + // Metadata for the PDF document + public DocumentMetadata GetMetadata() => new() + { + Title = "TarBall Sampling Form", + Author = "PAKAR SCIENO TW Integrated Environmental Solutions", + Subject = "Environmental Survey and Observations" + }; + + // Compose the PDF content + public void Compose(IDocumentContainer container) + { + container.Page(page => { - row.RelativeItem(1).Element(CellStyle).Column(column => + // Page Setup + page.Size(PageSizes.A4); + page.Margin(1.1f, Unit.Centimetre); + page.DefaultTextStyle(x => x.FontFamily("Arial").FontSize(10)); + + // Header Section + page.Header().Row(row => { + row.RelativeItem(1).Element(CellStyle).Column(column => + { + column.Item() + .AlignMiddle() + .AlignCenter() + .Text("Logo Placeholder"); + }); + + row.RelativeItem(1).Element(CellStyle) + .AlignMiddle() + .AlignCenter() + .Text("TARBALL SAMPLING FORM") + .FontSize(16) + .FontColor("#4B0082"); + + row.RelativeItem(1).Column(column => + { + column.Spacing(0); + + column.Item().Row(innerRow => + { + innerRow.RelativeItem(1).Element(CellStyle).Text("Document:") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("F-MM06") + .AlignLeft().Bold(); + }); + column.Item().Row(innerRow => + { + innerRow.RelativeItem(1).Element(CellStyle).Text("Effective Date:") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("1 April 2025") + .AlignLeft(); + }); + column.Item().Row(innerRow => + { + innerRow.RelativeItem(1).Element(CellStyle).Text("Revision No.") + .AlignLeft(); + innerRow.RelativeItem(1).Element(CellStyle).Text("02") + .AlignLeft(); + }); + }); + + static IContainer CellStyle(IContainer container) + => container.Border(0.5f).Padding(5); + }); + + // Content Section + page.Content().Column(column => + { + // Observations Table + column.Item().Element(container => + { + container + .PaddingTop(20) + .PaddingBottom(10) + .Text("Please be informed that we have observed the following conditions:"); + }); + column.Item().Table(table => + { + column.Spacing(0); + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(3); + columns.RelativeColumn(3); + }); + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATE") + .Bold(); + table.Cell().Element(CellStyle).Text(_stateName); + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATION ID") + .Bold(); + table.Cell().Element(CellStyle).Text(_stationId); + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("LOCATION") + .Bold(); + table.Cell().Element(CellStyle).Text(""); + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("TARBALL SURVEY LOCATION LONGITUDE & LATITUDE") + .Bold(); + table.Cell().Element(CellStyle).Text(""); + + table.Cell() + .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("DATE / TIME") + .Bold(); + table.Cell().Element(CellStyle).Text(""); + }); + + column.Spacing(3); + + // Survey Findings column.Item() - .AlignMiddle() // Ensures vertical centering - .AlignCenter() // Ensures horizontal centering - .Text("Logo Placeholder"); // Placeholder for the logo - }); - - row.RelativeItem(1).Element(CellStyle) - .AlignMiddle() // Ensures vertical centering - .AlignCenter() // Ensures horizontal centering - .Text("TARBALL SAMPLING FORM") - .FontSize(16) - .FontColor("#4B0082"); - - row.RelativeItem(1).Column(column => - { - column.Spacing(0); // Adds consistent spacing between rows - - // Document Row - column.Item().Row(innerRow => - { - innerRow.RelativeItem(1).Element(CellStyle).Text("Document:") - .AlignLeft(); - innerRow.RelativeItem(1).Element(CellStyle).Text("F-MM06") - .AlignLeft().Bold(); - }); - column.Item().Row(innerRow => - { - innerRow.RelativeItem(1).Element(CellStyle).Text("Effective Date:") - .AlignLeft(); - innerRow.RelativeItem(1).Element(CellStyle).Text("1 April 2025") - .AlignLeft(); - }); - column.Item().Row(innerRow => - { - innerRow.RelativeItem(1).Element(CellStyle).Text("Revision No.") - .AlignLeft(); - innerRow.RelativeItem(1).Element(CellStyle).Text("02") - .AlignLeft(); - }); - - }); - - // Define styles - static IContainer CellStyle(IContainer container) - => container.Border(0.5f).Padding(5); // Retains padding for text - }); - - // Content Section - page.Content().Column(column => - { - // Observations Table - column.Item().Element(container => - { - container - .PaddingTop(20) // Adds space above the text + .PaddingTop(10) .PaddingBottom(10) - .Text("Please be informed that we have observed the following conditions:"); - }); - column.Item().Table(table => - { - column.Spacing(0); + .Text("SURVEY FINDING:") + .Bold().FontSize(12); + column.Item() + .PaddingBottom(10) + .Text("Tar Ball: [☐] YES [☐] NO").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("If YES, Tar Ball falls under the classification of:").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("[☐] Sand [☐] Non-sandy [☐] Coquina").FontSize(10); + column.Item() + .PaddingBottom(10) + .Text("*tick wherever applicable"); - table.ColumnsDefinition(columns => + // Photos Section Title + column.Item() + .PaddingBottom(5) + .Text("PHOTOGRAPHS OF SAMPLING") + .AlignCenter() + .Bold() + .FontSize(14); + + // Table for Photos + column.Item().Table(table => { - columns.RelativeColumn(3); // Label/Header column - columns.RelativeColumn(3); // Data Entry column + column.Spacing(0); + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(1); + columns.RelativeColumn(1); + }); + + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 1: Left Side Coastal View").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 2: Right Side Coastal View").FontSize(12).AlignLeft(); + + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 3: Drawing Vertical Lines").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 4: Drawing Horizontal Lines (Racking)").FontSize(12).AlignLeft(); }); - // Table Rows - table.Cell() - .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATE") - .Bold(); - table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry + // Page Break + column.Item().PageBreak(); - table.Cell() - .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("STATION ID") - .Bold(); - table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry - - table.Cell() - .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("LOCATION") - .Bold(); - table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry - - table.Cell() - .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("TARBALL SURVEY LOCATION LONGITUDE & LATITUDE") - .Bold(); - table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry - - table.Cell() - .Background(Colors.Grey.Lighten2).Element(CellStyle).Text("DATE / TIME") - .Bold(); - table.Cell().Element(CellStyle).Text(""); // Empty cell for data entry - }); - - column.Spacing(3); - - // Survey Findings - column.Item() - .PaddingTop(10) // Adds space above the text - .PaddingBottom(10) - .Text("SURVEY FINDING:") - .Bold().FontSize(12); - column.Item() - .PaddingBottom(10) - .Text("Tar Ball: [☐] YES [☐] NO").FontSize(10); - column.Item() - .PaddingBottom(10) - .Text("If YES, Tar Ball falls under the classification of:").FontSize(10); - column.Item() - .PaddingBottom(10) - .Text("[☐] Sand [☐] Non-sandy [☐] Coquina").FontSize(10); - column.Item() - .PaddingBottom(10) - .Text("*tick wherever applicable"); - - // Photos Section Title - column.Item() - .PaddingBottom(5) - .Text("PHOTOGRAPHS OF SAMPLING") - .AlignCenter() // Ensures horizontal centering - .Bold() - .FontSize(14); - - // Table for Photos with Existing Heights - column.Item().Table(table => - { - column.Spacing(0); // No extra spacing between rows - - table.ColumnsDefinition(columns => + // Additional Photos Section + column.Item().Table(table => { - columns.RelativeColumn(1); // First column - columns.RelativeColumn(1); // Second column + column.Spacing(0); + + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(1); + columns.RelativeColumn(1); + }); + + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 5:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 6:").FontSize(12).AlignLeft(); + + table.Cell().Element(CellStyle).Height(150); + table.Cell().Element(CellStyle).Height(150); + + table.Cell().Element(CellStyle).Text("Figure 7:").FontSize(12).AlignLeft(); + table.Cell().Element(CellStyle).Text("Figure 8:").FontSize(12).AlignLeft(); }); - // For pictures - table.Cell().Element(CellStyle).Height(150); - table.Cell().Element(CellStyle).Height(150); + // Note Section + column.Item() + .PaddingTop(10) + .PaddingBottom(20) + .Text("* If there are any event observe at the current station it is compulsory to add optional photo with description (figure 5 to figure 8)") + .FontSize(10) + .AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 1: Left Side Coastal View").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 2: Right Side Coastal View").FontSize(12).AlignLeft(); - - table.Cell().Element(CellStyle).Height(150); - table.Cell().Element(CellStyle).Height(150); - - table.Cell().Element(CellStyle).Text("Figure 3: Drawing Vertical Lines").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 4: Drawing Horizontal Lines (Racking)").FontSize(12).AlignLeft(); - }); - - // Page Break - column.Item().PageBreak(); - - // Additional Photos Section - column.Item() - .PaddingBottom(5) - .AlignCenter(); // Ensures horizontal centering - - // Table for Additional Photos - column.Item().Table(table => - { - column.Spacing(0); // No extra spacing between rows - - table.ColumnsDefinition(columns => + // Signature Section + column.Item().Table(table => { - columns.RelativeColumn(1); // First column - columns.RelativeColumn(1); // Second column + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(2); + columns.RelativeColumn(1); + columns.RelativeColumn(2); + columns.RelativeColumn(1); + columns.RelativeColumn(1); + }); + + table.Cell().RowSpan(2).Element(CellStyle).Text("REPORTED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text(""); + + table.Cell().RowSpan(2).Element(CellStyle).Text("CHECKED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text(""); + + table.Cell().RowSpan(2).Element(CellStyle).Text("VERIFIED BY :").Bold().FontSize(12); + table.Cell().Element(CellStyle).Text("Signature").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + table.Cell().Element(CellStyle).Text("Date").FontSize(12); + table.Cell().Element(CellStyle).Text(""); + + table.Cell().Element(CellStyle).Text("Designation").FontSize(12); + table.Cell().ColumnSpan(3).Element(CellStyle).Text(""); }); - - // Row 1: Empty spaces for pictures - table.Cell().Element(CellStyle).Height(150); - table.Cell().Element(CellStyle).Height(150); - - // Row 2: Labels for the pictures - table.Cell().Element(CellStyle).Text("Figure 5:").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 6:").FontSize(12).AlignLeft(); - - // Row 3: Empty spaces for pictures - table.Cell().Element(CellStyle).Height(150); - table.Cell().Element(CellStyle).Height(150); - - // Row 4: Labels for the pictures - table.Cell().Element(CellStyle).Text("Figure 7:").FontSize(12).AlignLeft(); - table.Cell().Element(CellStyle).Text("Figure 8:").FontSize(12).AlignLeft(); }); - // Note Section - column.Item() - .PaddingTop(10) - .PaddingBottom(20) - .Text("* If there are any event observe at the current station it is compulsory to add optional photo with description (figure 5 to figure 8)") - .FontSize(10) - .AlignLeft(); - - // Signature Section - column.Item().Table(table => + // Footer Section + page.Footer().AlignCenter().Text(text => { - //define how many columns the table has - table.ColumnsDefinition(columns => - { - columns.RelativeColumn(2); // Label column - columns.RelativeColumn(1); // Signature column - columns.RelativeColumn(2); //empty - columns.RelativeColumn(1); // Date column - columns.RelativeColumn(1); //empty - }); - - // Signature Rows - table.Cell().RowSpan(2).Element(CellStyle).Text("REPORTED BY :").Bold().FontSize(12); - table.Cell().Element(CellStyle).Text("Signature").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - table.Cell().Element(CellStyle).Text("Date").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - - table.Cell().Element(CellStyle).Text("Designation").FontSize(12); - table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); - - table.Cell().RowSpan(2).Element(CellStyle).Text("CHECKED BY :").Bold().FontSize(12); - table.Cell().Element(CellStyle).Text("Signature").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - table.Cell().Element(CellStyle).Text("Date").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - - table.Cell().Element(CellStyle).Text("Designation").FontSize(12); - table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); - - table.Cell().RowSpan(2).Element(CellStyle).Text("VERIFIED BY :").Bold().FontSize(12); - table.Cell().Element(CellStyle).Text("Signature").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - table.Cell().Element(CellStyle).Text("Date").FontSize(12); - table.Cell().Element(CellStyle).Text("").FontSize(12); - - table.Cell().Element(CellStyle).Text("Designation").FontSize(12); - table.Cell().ColumnSpan(3).Element(CellStyle).Text("").FontSize(12); + text.Span("Page "); + text.CurrentPageNumber(); + text.Span(" of "); + text.TotalPages(); }); + + static IContainer CellStyle(IContainer container) => container.Border(0.5f).Padding(5); }); - - // Footer Section - page.Footer().AlignCenter().Text(text => - { - text.Span("Page "); - text.CurrentPageNumber(); - text.Span(" of "); - text.TotalPages(); - }); - static IContainer CellStyle(IContainer container) => container.Border(0.5f) - .Padding(5); - }); + } } } diff --git a/Areas/MMS/Views/Marine/TarBallForm.cshtml b/Areas/MMS/Views/Marine/TarBallForm.cshtml index cfd611d..8313817 100644 --- a/Areas/MMS/Views/Marine/TarBallForm.cshtml +++ b/Areas/MMS/Views/Marine/TarBallForm.cshtml @@ -86,14 +86,15 @@ No. Date - - + + Station - - + + + Status PDF @@ -133,7 +134,7 @@ 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], - dataFromServer: @Html.Raw(Json.Serialize(Model)) + dataFromServer: @Html.Raw(Json.Serialize(Model ?? new List())) }, computed: { years() { diff --git a/DBContext/MMSSystemContext.cs b/DBContext/MMSSystemContext.cs index e751051..d328fd6 100644 --- a/DBContext/MMSSystemContext.cs +++ b/DBContext/MMSSystemContext.cs @@ -11,6 +11,9 @@ namespace PSTW_CentralSystem.DBContext // DbSet for tbl_marine_tarball public DbSet MarineTarballs { get; set; } + public DbSet TarballStations { get; set; } + public DbSet States { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -36,7 +39,46 @@ namespace PSTW_CentralSystem.DBContext entity.Property(e => e.GetLatitude).HasColumnName("getLatitude"); entity.Property(e => e.GetLongitude).HasColumnName("getLongitude"); entity.Property(e => e.Timestamp).HasColumnName("timestamp"); + + //Configure relationship with TarballStation + entity.HasOne(m => m.TarballStation) + .WithMany() + .HasForeignKey(m => m.StationID) + .HasPrincipalKey(t => t.StationID); }); + + // Map TarballStation to tbl_tarball_station + modelBuilder.Entity().ToTable("tbl_tarball_station"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); // Primary key + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.StationID).HasColumnName("stationID").HasMaxLength(20); + entity.Property(e => e.StateID).HasColumnName("stateID").HasMaxLength(10); + entity.Property(e => e.CategoryID).HasColumnName("categoryID").HasMaxLength(10); + entity.Property(e => e.LocationName).HasColumnName("locationName").HasMaxLength(50); + entity.Property(e => e.Longitude).HasColumnName("longitude").HasColumnType("decimal(10,5)"); + entity.Property(e => e.Latitude).HasColumnName("latitude").HasColumnType("decimal(10,5)"); + + // Configure relationship with State + entity.HasOne(t => t.State) + .WithMany() + .HasForeignKey(t => t.StateID) + .HasPrincipalKey(s => s.StateID); + }); + + // Map State to tbl_state + modelBuilder.Entity().ToTable("tbl_state"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id); // Primary key + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.StateID).HasColumnName("stateID").HasMaxLength(20); + entity.Property(e => e.StateName).HasColumnName("stateName").HasMaxLength(50); + }); + } } } diff --git a/Models/MarineTarball.cs b/Models/MarineTarball.cs index 9f7322c..af318e6 100644 --- a/Models/MarineTarball.cs +++ b/Models/MarineTarball.cs @@ -1,21 +1,48 @@ -using System; +using System.ComponentModel.DataAnnotations.Schema; namespace PSTW_CentralSystem.Models { public class MarineTarball { public int Id { get; set; } // Maps to 'id' - public string ReportID { get; set; } // Maps to 'reportID' - public string FirstSampler { get; set; } // Maps to 'firstSampler' - public string SecondSampler { get; set; } // Maps to 'secondSampler' + public required string ReportID { get; set; } // Maps to 'reportID' + public required string FirstSampler { get; set; } // Maps to 'firstSampler' + public required string SecondSampler { get; set; } // Maps to 'secondSampler' public DateTime DateSample { get; set; } // Maps to 'dateSample' public TimeSpan TimeSample { get; set; } // Maps to 'timeSample' - public string StationID { get; set; } // Maps to 'stationID' - public string ClassifyID { get; set; } // Maps to 'classifyID' + public required string StationID { get; set; } // Maps to 'stationID' + public required string ClassifyID { get; set; } // Maps to 'classifyID' public double Latitude { get; set; } // Maps to 'latitude' public double Longitude { get; set; } // Maps to 'longitude' public double GetLatitude { get; set; } // Maps to 'getLatitude' public double GetLongitude { get; set; } // Maps to 'getLongitude' public DateTime Timestamp { get; set; } // Maps to 'timestamp' + + [ForeignKey("StationID")] + public required TarballStation TarballStation { get; set; } } + + public class TarballStation + { + public int Id { get; set; } // Maps to 'id' + public required string StationID { get; set; } // Maps to 'stationID' + public required string StateID { get; set; } // Maps to 'stateID' + public required string CategoryID { get; set; } // Maps to 'categoryID' + public required string LocationName { get; set; } // Maps to 'locationName' + public decimal Longitude { get; set; } // Maps to 'longitude' + public decimal Latitude { get; set; } // Maps to 'latitude' + + [ForeignKey("StateID")] + public required State State { get; set; } + + } + + public class State + { + public int Id { get; set; } // Maps to 'id' + public required string StateID { get; set; } // Maps to 'stateID' + public required string StateName { get; set; } // Maps to 'stateName' + } + } +