diff --git a/src/PowderCoating.Web/Controllers/CompanySettingsController.cs b/src/PowderCoating.Web/Controllers/CompanySettingsController.cs index 3126406..7dad626 100644 --- a/src/PowderCoating.Web/Controllers/CompanySettingsController.cs +++ b/src/PowderCoating.Web/Controllers/CompanySettingsController.cs @@ -230,11 +230,19 @@ public class CompanySettingsController : Controller return Json(new { success = false, message = "Company not found." }); } - // Update company properties - _mapper.Map(dto, company); - company.UpdatedAt = DateTime.UtcNow; + // Explicit assignment avoids AutoMapper quirks with tracked EF entities + company.CompanyName = dto.CompanyName.Trim(); + company.CompanyCode = string.IsNullOrWhiteSpace(dto.CompanyCode) ? null : dto.CompanyCode.Trim(); + company.PrimaryContactName = dto.PrimaryContactName.Trim(); + company.PrimaryContactEmail = dto.PrimaryContactEmail.Trim(); + company.Phone = string.IsNullOrWhiteSpace(dto.Phone) ? null : dto.Phone.Trim(); + company.Address = string.IsNullOrWhiteSpace(dto.Address) ? null : dto.Address.Trim(); + company.City = string.IsNullOrWhiteSpace(dto.City) ? null : dto.City.Trim(); + company.State = string.IsNullOrWhiteSpace(dto.State) ? null : dto.State.Trim(); + company.ZipCode = string.IsNullOrWhiteSpace(dto.ZipCode) ? null : dto.ZipCode.Trim(); + company.TimeZone = string.IsNullOrWhiteSpace(dto.TimeZone) ? null : dto.TimeZone.Trim(); + company.AccountingMethod = dto.AccountingMethod; - await _unitOfWork.Companies.UpdateAsync(company); await _unitOfWork.CompleteAsync(); _logger.LogInformation("Company {CompanyId} settings updated by user", companyId); diff --git a/src/PowderCoating.Web/Views/CompanySettings/Index.cshtml b/src/PowderCoating.Web/Views/CompanySettings/Index.cshtml index 1151807..a9cffca 100644 --- a/src/PowderCoating.Web/Views/CompanySettings/Index.cshtml +++ b/src/PowderCoating.Web/Views/CompanySettings/Index.cshtml @@ -312,7 +312,7 @@
-
@@ -2749,10 +2749,8 @@ } }); - // Company Info Form Submit - $('#companyInfoForm').on('submit', function (e) { - e.preventDefault(); - + // Company Info Save + $('#btnSaveCompanyInfo').on('click', function () { const formData = { CompanyName: $('#companyName').val(), CompanyCode: $('#companyCode').val(), @@ -3192,7 +3190,7 @@ // Button success animation helper function showButtonSuccess(btn, originalHtml, duration = 2000) { - btn.removeClass('btn-primary').addClass('btn-success'); + btn.prop('disabled', false).removeClass('btn-primary').addClass('btn-success'); btn.html(' Saved!'); setTimeout(function() { btn.removeClass('btn-success').addClass('btn-primary');