From 93fa76a5aa51eebcb1977529f9cf96250bbb7e9c Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 16 Apr 2026 17:15:28 -0400 Subject: [PATCH] Handle string-to-int AccountId conversion in Location DTOs - Frontend sends accountId as empty string when not set - Change DTO AccountId to string with GetAccountId() parser - Prevents JSON deserialization error on empty/non-numeric values --- Api.SeaHavenIndustries/Controllers/LocationController.cs | 4 ++-- Api.SeaHavenIndustries/DTOs/EditLocation_DTO.cs | 5 ++++- Api.SeaHavenIndustries/DTOs/Location_DTO.cs | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Api.SeaHavenIndustries/Controllers/LocationController.cs b/Api.SeaHavenIndustries/Controllers/LocationController.cs index 202a956..9dbb485 100644 --- a/Api.SeaHavenIndustries/Controllers/LocationController.cs +++ b/Api.SeaHavenIndustries/Controllers/LocationController.cs @@ -114,7 +114,7 @@ namespace Api.SeaHavenIndustries.Controllers Contact = model.Contact, ContactEmail = model.ContactEmail, Status = model.Status, - AccountId = model.AccountId + AccountId = model.GetAccountId() }; _db.Locations.Add(location); @@ -146,7 +146,7 @@ namespace Api.SeaHavenIndustries.Controllers exist.Contact = model.Contact; exist.ContactEmail = model.ContactEmail; exist.Status = model.Status; - exist.AccountId = model.AccountId; + exist.AccountId = model.GetAccountId(); await _db.SaveChangesAsync(); return Ok(new DataResponse { Message = "Location Updated Successfully", Status = "200" }); diff --git a/Api.SeaHavenIndustries/DTOs/EditLocation_DTO.cs b/Api.SeaHavenIndustries/DTOs/EditLocation_DTO.cs index ad26a9e..fc17b09 100644 --- a/Api.SeaHavenIndustries/DTOs/EditLocation_DTO.cs +++ b/Api.SeaHavenIndustries/DTOs/EditLocation_DTO.cs @@ -13,6 +13,9 @@ namespace Api.SeaHavenIndustries.DTOs public string? Contact { get; set; } public string? ContactEmail { get; set; } public string? Status { get; set; } - public int? AccountId { get; set; } + public string? AccountId { get; set; } + + public int? GetAccountId() => + int.TryParse(AccountId, out var id) ? id : null; } } diff --git a/Api.SeaHavenIndustries/DTOs/Location_DTO.cs b/Api.SeaHavenIndustries/DTOs/Location_DTO.cs index 079687c..e023062 100644 --- a/Api.SeaHavenIndustries/DTOs/Location_DTO.cs +++ b/Api.SeaHavenIndustries/DTOs/Location_DTO.cs @@ -12,6 +12,9 @@ namespace Api.SeaHavenIndustries.DTOs public string? Contact { get; set; } public string? ContactEmail { get; set; } public string? Status { get; set; } - public int? AccountId { get; set; } + public string? AccountId { get; set; } + + public int? GetAccountId() => + int.TryParse(AccountId, out var id) ? id : null; } }