diff --git a/Areas/MMS/Controllers/MarineController.cs b/Areas/MMS/Controllers/MarineController.cs index 2095ee5..68c3262 100644 --- a/Areas/MMS/Controllers/MarineController.cs +++ b/Areas/MMS/Controllers/MarineController.cs @@ -10,10 +10,11 @@ using System.Threading; using System.Collections.Generic; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; +using MySqlConnector; namespace PSTW_CentralSystem.Areas.MMS.Controllers { - public class SimpleTarballDto + public class TarballPdfDto { // From tbl_marine_tarball public int Id { get; set; } @@ -58,8 +59,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers { try { - var marineTarballs = _context.MarineTarballs //error=========================================== - .Where(t => t.StationID != "1") // To remove unusable data with invalid stationID + var marineTarballs = _context.MarineTarballs //ERRORRRRRRR====================================== .Select(t => new { t.Id, @@ -287,7 +287,7 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers WHERE marine.Id = @id"; var tarball = await _context.Database - .SqlQueryRaw(query, new SqlParameter("@id", id)) + .SqlQueryRaw(query, new MySqlParameter("@id", id)) .FirstOrDefaultAsync(); if (tarball == null) @@ -413,31 +413,6 @@ namespace PSTW_CentralSystem.Areas.MMS.Controllers } } - // Add this class outside your controller (e.g., in a DTOs folder) - public class TarballPdfDto - { - public string StateName { get; set; } - public string StationID { get; set; } - public string LocationName { get; set; } - public string Longitude { get; set; } - public string Latitude { get; set; } - public DateTime DateSample { get; set; } - public TimeSpan TimeSample { get; set; } - public string ClassifyID { get; set; } - public int TarBallYes { get; set; } // SQL returns 1/0 for bits - public int TarBallNo { get; set; } - public int IsSand { get; set; } - public int IsNonSandy { get; set; } - public int IsCoquina { get; set; } - public string OptionalName1 { get; set; } - public string OptionalName2 { get; set; } - public string OptionalName3 { get; set; } - public string OptionalName4 { get; set; } - public string FirstSampler { get; set; } - public string FullName { get; set; } - public string LevelName { get; set; } - } - private bool IsImageValid(string imagePath) { try diff --git a/DBContext/MMSSystemContext.cs b/DBContext/MMSSystemContext.cs index 95abc40..bf5474e 100644 --- a/DBContext/MMSSystemContext.cs +++ b/DBContext/MMSSystemContext.cs @@ -46,12 +46,16 @@ namespace PSTW_CentralSystem.DBContext entity.Property(e => e.OptionalName4).HasColumnName("optionalName4"); entity.Property(e => e.Timestamp).HasColumnName("timestamp"); + entity.HasOne(t => t.User) + .WithMany() + .HasForeignKey(t => t.FirstSampler) + .HasPrincipalKey(u => u.FullName); // Assuming User has FullName + //Configure relationship with TarballStation entity.HasOne(m => m.MarineStation) .WithMany() .HasForeignKey(m => m.StationID) .HasPrincipalKey(t => t.StationID); - }); modelBuilder.Entity(entity => diff --git a/Models/MarineTarball.cs b/Models/MarineTarball.cs index fd55026..9321a85 100644 --- a/Models/MarineTarball.cs +++ b/Models/MarineTarball.cs @@ -34,7 +34,7 @@ namespace PSTW_CentralSystem.Models [ForeignKey("StationID")] public required MarineStation MarineStation { get; set; } [ForeignKey("FirstSampler")] - public required MarineStation User { get; set; } + public required User User { get; set; } } public class MarineStation