From 916a176260f390e8227626bcd90c8cdadebc4e7c Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Thu, 2 Jan 2025 02:17:41 -0800 Subject: [PATCH] PSP-9683 Generated H-120 Compensation Requisition not Populating Electoral District (#4564) * Code cleanup * PSP-9683 Return compensation property locations in lat/long * Test updates --- .../CompensationRequisitionController.cs | 8 +- .../CompensationRequisitionService.cs | 16 +- .../CompReqFinancialRepository.cs | 2 +- .../CompensationRequisitionRepository.cs | 4 +- .../CompensationRequisitionServiceTest.cs | 129 ++++++++- .../CompensationRequisitionRepositoryTest.cs | 272 ++++++++++++++++++ .../ConsultationRepositoryTest.cs | 2 +- 7 files changed, 409 insertions(+), 24 deletions(-) create mode 100644 source/backend/tests/unit/dal/Repositories/CompensationRequisitionRepositoryTest.cs diff --git a/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs b/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs index 0248f787b7..d1bcd51f94 100644 --- a/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs +++ b/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs @@ -4,17 +4,17 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Pims.Core.Api.Exceptions; using Pims.Api.Models.CodeTypes; using Pims.Api.Models.Concepts.AcquisitionFile; using Pims.Api.Models.Concepts.CompensationRequisition; using Pims.Api.Models.Concepts.Lease; -using Pims.Core.Api.Policies; using Pims.Api.Services; +using Pims.Core.Api.Exceptions; +using Pims.Core.Api.Policies; using Pims.Core.Extensions; using Pims.Core.Json; -using Pims.Dal.Entities; using Pims.Core.Security; +using Pims.Dal.Entities; using Swashbuckle.AspNetCore.Annotations; namespace Pims.Api.Areas.CompensationRequisition.Controllers @@ -189,7 +189,7 @@ public IActionResult DeleteCompensation([FromRoute] long id) [ProducesResponseType(typeof(List), 200)] [SwaggerOperation(Tags = new[] { "compensation-requisition" })] [TypeFilter(typeof(NullJsonResultFilter))] - public IActionResult GetFileCompensations([FromRoute]FileTypes fileType, [FromRoute]long fileId) + public IActionResult GetFileCompensations([FromRoute] FileTypes fileType, [FromRoute] long fileId) { _logger.LogInformation( "Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", diff --git a/source/backend/api/Services/CompensationRequisitionService.cs b/source/backend/api/Services/CompensationRequisitionService.cs index a4bd9df995..74ae0bd5a2 100644 --- a/source/backend/api/Services/CompensationRequisitionService.cs +++ b/source/backend/api/Services/CompensationRequisitionService.cs @@ -3,15 +3,14 @@ using System.Linq; using System.Security.Claims; using Microsoft.Extensions.Logging; -using Pims.Core.Api.Exceptions; using Pims.Api.Models.CodeTypes; +using Pims.Core.Api.Exceptions; using Pims.Core.Exceptions; using Pims.Core.Extensions; +using Pims.Core.Security; using Pims.Dal.Entities; using Pims.Dal.Entities.Extensions; -using Pims.Dal.Helpers.Extensions; using Pims.Dal.Repositories; -using Pims.Core.Security; namespace Pims.Api.Services { @@ -26,6 +25,7 @@ public class CompensationRequisitionService : ICompensationRequisitionService private readonly ICompReqFinancialService _compReqFinancialService; private readonly IAcquisitionStatusSolver _acquisitionStatusSolver; private readonly ILeaseRepository _leaseRepository; + private readonly IPropertyService _propertyService; public CompensationRequisitionService( ClaimsPrincipal user, @@ -36,7 +36,8 @@ public CompensationRequisitionService( IAcquisitionFileRepository acqFileRepository, ICompReqFinancialService compReqFinancialService, IAcquisitionStatusSolver statusSolver, - ILeaseRepository leaseRepository) + ILeaseRepository leaseRepository, + IPropertyService propertyService) { _user = user; _logger = logger; @@ -47,6 +48,7 @@ public CompensationRequisitionService( _compReqFinancialService = compReqFinancialService; _acquisitionStatusSolver = statusSolver; _leaseRepository = leaseRepository; + _propertyService = propertyService; } public PimsCompensationRequisition GetById(long compensationRequisitionId) @@ -121,7 +123,8 @@ public IEnumerable GetAcquisitionProperties(long id _logger.LogInformation("Getting properties for Compensation Requisition with id {id}", id); _user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionView); - return _compensationRequisitionRepository.GetAcquisitionCompReqPropertiesById(id); + var properties = _compensationRequisitionRepository.GetAcquisitionCompReqPropertiesById(id); + return _propertyService.TransformAllPropertiesToLatLong(properties); } public IEnumerable GetLeaseProperties(long id) @@ -129,7 +132,8 @@ public IEnumerable GetLeaseProperties(long id) _logger.LogInformation("Getting properties for Compensation Requisition with id {id}", id); _user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionView); - return _compensationRequisitionRepository.GetLeaseCompReqPropertiesById(id); + var propertyLeases = _compensationRequisitionRepository.GetLeaseCompReqPropertiesById(id); + return _propertyService.TransformAllPropertiesToLatLong(propertyLeases); } public IEnumerable GetFileCompensationRequisitions(FileTypes fileType, long fileId) diff --git a/source/backend/dal/Repositories/CompReqFinancialRepository.cs b/source/backend/dal/Repositories/CompReqFinancialRepository.cs index a80bd59684..9099c5820d 100644 --- a/source/backend/dal/Repositories/CompReqFinancialRepository.cs +++ b/source/backend/dal/Repositories/CompReqFinancialRepository.cs @@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Pims.Core.Exceptions; +using Pims.Core.Extensions; using Pims.Core.Security; using Pims.Dal.Entities; using Pims.Dal.Entities.Models; -using Pims.Core.Extensions; using Pims.Dal.Helpers.Extensions; namespace Pims.Dal.Repositories diff --git a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs index eadd62f192..0ed6a06ffa 100644 --- a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs +++ b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs @@ -142,7 +142,7 @@ public List GetAcquisitionCompReqPropertiesById(lon { return Context.PimsPropAcqFlCompReqs .Where(x => x.CompensationRequisitionId == compensationRequisitionId) - .Include(pa => pa.PropertyAcquisitionFile) + .Include(pa => pa.PropertyAcquisitionFile) .ThenInclude(p => p.Property) .ThenInclude(rp => rp.RegionCodeNavigation) .Include(pa => pa.PropertyAcquisitionFile) @@ -165,7 +165,7 @@ public List GetLeaseCompReqPropertiesById(long compensationRe { return Context.PimsPropLeaseCompReqs .Where(x => x.CompensationRequisitionId == compensationRequisitionId) - .Include(l => l.PropertyLease) + .Include(l => l.PropertyLease) .ThenInclude(p => p.Property) .ThenInclude(rp => rp.RegionCodeNavigation) .Include(pa => pa.PropertyLease) diff --git a/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs b/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs index 9675b4d833..e6fe030e77 100644 --- a/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs +++ b/source/backend/tests/unit/api/Services/CompensationRequisitionServiceTest.cs @@ -70,7 +70,55 @@ public void GetById_NoPermission() } [Fact] - public void GetPropertiesById_NoPermission() + public void GetAcquisitionProperties_Success() + { + // Arrange + var property = EntityHelper.CreateProperty(12345); + property.Location = new NetTopologySuite.Geometries.Point(1229480.4045231808, 463288.8298389828) { SRID = SpatialReference.BCALBERS }; + + var compReqProperty = new PimsPropAcqFlCompReq() + { + Internal_Id = 1, + CompensationRequisitionId = 1, + PropertyAcquisitionFileId = 1, + PropertyAcquisitionFile = new() + { + AcquisitionFileId = 1, + PropertyId = property.Internal_Id, + Property = property, + } + }; + + var service = CreateCompRequisitionServiceWithPermissions(Permissions.CompensationRequisitionView); + var repository = _helper.GetService>(); + repository.Setup(x => x.GetAcquisitionCompReqPropertiesById(It.IsAny())).Returns(new List() { compReqProperty.PropertyAcquisitionFile }); + // mock the spatial conversion to lat/long + var propertyService = _helper.GetService>(); + propertyService.Setup(x => x.TransformAllPropertiesToLatLong(It.IsAny>())) + .Returns>(x => x.Select(pp => + { + pp.Property.Location = new NetTopologySuite.Geometries.Point(-122, 49) { SRID = SpatialReference.WGS84 }; + return pp; + }).ToList()); + + // Act + var result = service.GetAcquisitionProperties(1); + + // Assert + repository.Verify(x => x.GetAcquisitionCompReqPropertiesById(It.IsAny()), Times.Once); + propertyService.Verify(x => x.TransformAllPropertiesToLatLong(It.IsAny>()), Times.Once); + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + result.First().Property.Pid.Should().Be(12345); + // service should perform spatial conversion to Lat/Long so that it can be returned to the frontend + result.First().Property.Location.SRID.Should().Be(SpatialReference.WGS84); + result.First().Property.Location.As().X.Should().Be(-122); + result.First().Property.Location.As().Y.Should().Be(49); + } + + [Fact] + public void GetAcquisitionProperties_NoPermission() { // Arrange var service = this.CreateCompRequisitionServiceWithPermissions(); @@ -82,6 +130,67 @@ public void GetPropertiesById_NoPermission() act.Should().Throw(); } + [Fact] + public void GetLeaseProperties_Success() + { + // Arrange + var property = EntityHelper.CreateProperty(12345); + property.Location = new NetTopologySuite.Geometries.Point(1229480.4045231808, 463288.8298389828) { SRID = SpatialReference.BCALBERS }; + + var leaseCompReqProperty = new PimsPropLeaseCompReq() + { + Internal_Id = 1, + CompensationRequisitionId = 1, + PropertyLeaseId = 1, + PropertyLease = new() + { + LeaseId = 1, + PropertyId = property.Internal_Id, + Property = property, + } + }; + + var service = CreateCompRequisitionServiceWithPermissions(Permissions.CompensationRequisitionView); + var repository = _helper.GetService>(); + repository.Setup(x => x.GetLeaseCompReqPropertiesById(It.IsAny())).Returns(new List() { leaseCompReqProperty.PropertyLease }); + // mock the spatial conversion to lat/long + var propertyService = _helper.GetService>(); + propertyService.Setup(x => x.TransformAllPropertiesToLatLong(It.IsAny>())) + .Returns>(x => x.Select(pp => + { + pp.Property.Location = new NetTopologySuite.Geometries.Point(-122, 49) { SRID = SpatialReference.WGS84 }; + return pp; + }).ToList()); + + // Act + var result = service.GetLeaseProperties(1); + + // Assert + repository.Verify(x => x.GetLeaseCompReqPropertiesById(It.IsAny()), Times.Once); + propertyService.Verify(x => x.TransformAllPropertiesToLatLong(It.IsAny>()), Times.Once); + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + result.First().Property.Pid.Should().Be(12345); + // service should perform spatial conversion to Lat/Long so that it can be returned to the frontend + result.First().Property.Location.SRID.Should().Be(SpatialReference.WGS84); + result.First().Property.Location.As().X.Should().Be(-122); + result.First().Property.Location.As().Y.Should().Be(49); + } + + [Fact] + public void GetLeaseProperties_NoPermission() + { + // Arrange + var service = this.CreateCompRequisitionServiceWithPermissions(); + + // Act + Action act = () => service.GetLeaseProperties(1); + + // Assert + act.Should().Throw(); + } + [Fact] public void GetById_Success() { @@ -152,7 +261,7 @@ public void GetCompensationsRequisitions_Success() [Theory] [MemberData(nameof(FileTypesDataNoAccess))] - public void AddCompensationsRequisitions_NoPermissions(FileTypes fileType,PimsCompensationRequisition compReq, Exception exception) + public void AddCompensationsRequisitions_NoPermissions(FileTypes fileType, PimsCompensationRequisition compReq, Exception exception) { // Arrange var service = this.CreateCompRequisitionServiceWithPermissions(); @@ -286,7 +395,7 @@ public void Update_NoPermission_AcquisitionFile() var service = this.CreateCompRequisitionServiceWithPermissions(); // Act - Action act = () => service.Update(FileTypes.Acquisition, new PimsCompensationRequisition() { CompensationRequisitionId = 1, AcquisitionFileId = 1}); + Action act = () => service.Update(FileTypes.Acquisition, new PimsCompensationRequisition() { CompensationRequisitionId = 1, AcquisitionFileId = 1 }); // Assert act.Should().Throw(); @@ -523,7 +632,7 @@ public void Update_Status_BackToDraft_AuthorizedAdmin() noteRepository.Verify(x => x.Add(It.Is(x => x.AcquisitionFileId == 1 && x.Note.NoteTxt.Equals("Compensation Requisition with # 1, changed status from 'Final' to 'Draft'"))), Times.Once); } - + [Fact] public void Update_Status_BackToNull_AuthorizedAdmin() { @@ -564,7 +673,7 @@ public void Update_Status_BackToNull_AuthorizedAdmin() noteRepository.Verify(x => x.Add(It.Is(x => x.AcquisitionFileId == 1 && x.Note.NoteTxt.Equals("Compensation Requisition with # 1, changed status from 'Final' to 'No Status'"))), Times.Once); } - + [Fact] public void Update_Success_Skips_StatusChanged_Note_FromNoStatus() { @@ -646,7 +755,7 @@ public void Update_Success_ValidTotalAllowableCompensation() result.Should().NotBeNull(); compRepository.Verify(x => x.Update(It.IsAny()), Times.Once); } - + [Fact] public void Update_Success_ValidMultipleTotalAllowableCompensation() { @@ -690,7 +799,7 @@ public void Update_Success_ValidMultipleTotalAllowableCompensation() result.Should().NotBeNull(); compRepository.Verify(x => x.Update(It.IsAny()), Times.Once); } - + [Fact] public void Update_Success_TotalAllowableExceededDraft() { @@ -732,7 +841,7 @@ public void Update_Success_TotalAllowableExceededDraft() result.Should().NotBeNull(); compRepository.Verify(x => x.Update(It.IsAny()), Times.Once); } - + [Fact] public void Update_Fail_TotalAllowableExceeded() { @@ -774,7 +883,7 @@ public void Update_Fail_TotalAllowableExceeded() }); act.Should().Throw(); } - + [Fact] public void Update_Fail_ValidMultipleTotalAllowableCompensation() { @@ -912,7 +1021,7 @@ public void Delete_NoPermission() // Assert act.Should().Throw(); } - + [Fact] public void Delete_Success() { diff --git a/source/backend/tests/unit/dal/Repositories/CompensationRequisitionRepositoryTest.cs b/source/backend/tests/unit/dal/Repositories/CompensationRequisitionRepositoryTest.cs new file mode 100644 index 0000000000..f9ac685c54 --- /dev/null +++ b/source/backend/tests/unit/dal/Repositories/CompensationRequisitionRepositoryTest.cs @@ -0,0 +1,272 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using FluentAssertions; +using Pims.Api.Models.CodeTypes; +using Pims.Core.Exceptions; +using Pims.Core.Security; +using Pims.Core.Test; +using Pims.Dal.Entities; +using Pims.Dal.Entities.Models; +using Pims.Dal.Exceptions; +using Pims.Dal.Repositories; +using Xunit; + +namespace Pims.Dal.Test.Repositories +{ + [Trait("category", "unit")] + [Trait("category", "dal")] + [Trait("group", "acquisition")] + [ExcludeFromCodeCoverage] + public class CompensationRequisitionRepositoryTest + { + // xUnit.net creates a new instance of the test class for every test that is run, + // so any code which is placed into the constructor of the test class will be run for every single test. + private readonly TestHelper _helper; + + public CompensationRequisitionRepositoryTest() + { + this._helper = new TestHelper(); + } + + private CompensationRequisitionRepository CreateWithPermissions(params Permissions[] permissions) + { + var user = PrincipalHelper.CreateForPermission(permissions); + this._helper.CreatePimsContext(user, true); + return this._helper.CreateRepository(user); + } + + [Fact] + public void GetAllByAcquisitionFileId_Success() + { + // Arrange + var compReq = new PimsCompensationRequisition() + { + IsDraft = true, + AcquisitionFileId = 1, + }; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(compReq); + + // Act + var result = repository.GetAllByAcquisitionFileId(1); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + } + + [Fact] + public void GetAllByLeaseFileId_Success() + { + // Arrange + var compReq = new PimsCompensationRequisition() + { + IsDraft = true, + LeaseId = 1, + }; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(compReq); + + // Act + var result = repository.GetAllByLeaseFileId(1); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + } + + [Fact] + public void AddCompensationRequisition_Success() + { + // Arrange + var repository = CreateWithPermissions(Permissions.LeaseEdit); + + // Act + var result = repository.Add(EntityHelper.CreateCompensationRequisition()); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + } + + [Fact] + public void GetById_Success() + { + // Arrange + var compReq = EntityHelper.CreateCompensationRequisition(id: 1); + compReq.AcquisitionFileId = 100; + + var repository = this.CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(compReq); + + // Act + var result = repository.GetById(1); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.Internal_Id.Should().Be(1); + } + + [Fact] + public void GetById_KeyNotFoundException() + { + // Arrange + var compReq = EntityHelper.CreateCompensationRequisition(id: 1); + compReq.AcquisitionFileId = 100; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(compReq); + + // Act + Action act = () => repository.GetById(2); + + // Assert + act.Should().Throw(); + } + + [Fact] + public void UpdateCompensationRequisition_Success() + { + // Arrange + var compReq = EntityHelper.CreateCompensationRequisition(id: 1); + compReq.AcquisitionFileId = 100; + compReq.LegacyPayee = "Legacy Payee (read-only)"; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionEdit); + _helper.AddAndSaveChanges(compReq); + + var updatedCompReq = EntityHelper.CreateCompensationRequisition(id: 1); + updatedCompReq.AcquisitionFileId = compReq.AcquisitionFileId; + updatedCompReq.FiscalYear = "2030/2031"; + updatedCompReq.LegacyPayee = "Attempting to modify legacy payee"; + + // Act + var result = repository.Update(updatedCompReq); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo(); + result.FiscalYear.Should().Be("2030/2031"); + result.LegacyPayee.Should().Be("Legacy Payee (read-only)"); // don't let frontend override legacy payee + } + + [Fact] + public void UpdateCompensationRequisition_KeyNotFoundException() + { + // Arrange + var updatedCompReq = EntityHelper.CreateCompensationRequisition(id: 1); + updatedCompReq.AcquisitionFileId = 100; + updatedCompReq.FiscalYear = "2030/2031"; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionEdit); + + // Act + Action act = () => repository.Update(updatedCompReq); + + // Assert + act.Should().Throw(); + } + + [Fact] + public void DeleteCompensationRequisition_Success() + { + // Arrange + var compReq = EntityHelper.CreateCompensationRequisition(id: 1); + compReq.AcquisitionFileId = 100; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionDelete); + var context = _helper.AddAndSaveChanges(compReq); + + // Act + context.ChangeTracker.Clear(); + var result = repository.TryDelete(compReq.Internal_Id); + context.CommitTransaction(); + + // Assert + result.Should().BeTrue(); + context.PimsCompensationRequisitions.Should().BeEmpty(); + } + + [Fact] + public void DeleteCompensationRequisition_NotFound() + { + // Arrange + var repository = CreateWithPermissions(Permissions.CompensationRequisitionDelete); + + // Act + var result = repository.TryDelete(1); + + // Assert + result.Should().BeFalse(); + } + + [Fact] + public void GetAcquisitionCompReqPropertiesById_Success() + { + // Arrange + var acquisitionCompReqProperty = new PimsPropAcqFlCompReq() + { + Internal_Id = 1, + CompensationRequisitionId = 1, + PropertyAcquisitionFileId = 1, + PropertyAcquisitionFile = new() + { + AcquisitionFileId = 1, + PropertyId = 12345, + Property = EntityHelper.CreateProperty(12345), + } + }; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(acquisitionCompReqProperty); + + // Act + var result = repository.GetAcquisitionCompReqPropertiesById(1); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + result.First().Property.Pid.Should().Be(12345); + result.First().Property.Location.SRID.Should().Be(SpatialReference.BCALBERS); // repository should return property location in BCALBERS projection + } + + [Fact] + public void GetLeaseCompReqPropertiesById_Success() + { + // Arrange + var leaseCompReqProperty = new PimsPropLeaseCompReq() + { + Internal_Id = 1, + CompensationRequisitionId = 1, + PropertyLeaseId = 1, + PropertyLease = new() + { + LeaseId = 1, + PropertyId = 12345, + Property = EntityHelper.CreateProperty(12345), + } + }; + + var repository = CreateWithPermissions(Permissions.CompensationRequisitionView); + _helper.AddAndSaveChanges(leaseCompReqProperty); + + // Act + var result = repository.GetLeaseCompReqPropertiesById(1); + + // Assert + result.Should().NotBeNull(); + result.Should().BeAssignableTo>(); + result.Should().HaveCount(1); + result.First().Property.Pid.Should().Be(12345); + result.First().Property.Location.SRID.Should().Be(SpatialReference.BCALBERS); // repository should return property location in BCALBERS projection + } + } +} diff --git a/source/backend/tests/unit/dal/Repositories/ConsultationRepositoryTest.cs b/source/backend/tests/unit/dal/Repositories/ConsultationRepositoryTest.cs index 2c556fbe09..2d337e7b47 100644 --- a/source/backend/tests/unit/dal/Repositories/ConsultationRepositoryTest.cs +++ b/source/backend/tests/unit/dal/Repositories/ConsultationRepositoryTest.cs @@ -90,7 +90,7 @@ public void UpdateConsultation_Success() // Arrange var repository = CreateWithPermissions(Permissions.LeaseEdit); var consultation = EntityHelper.CreateLeaseConsultationItem(); - + _helper.AddAndSaveChanges(consultation); var updatedConsultation = EntityHelper.CreateLeaseConsultationItem();