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
This commit is contained in:
Adam Moussa 2026-04-16 17:15:28 -04:00
parent 5a20e55138
commit 93fa76a5aa
3 changed files with 10 additions and 4 deletions

View file

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

View file

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

View file

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