public void ApplyUpdate(Apprenticeship apprenticeship, ApprenticeshipUpdate update) { apprenticeship.FirstName = string.IsNullOrEmpty(update.FirstName) ? apprenticeship.FirstName : update.FirstName; apprenticeship.LastName = string.IsNullOrEmpty(update.LastName) ? apprenticeship.LastName : update.LastName; apprenticeship.TrainingType = update.TrainingType ?? apprenticeship.TrainingType; if (!string.IsNullOrEmpty(update.TrainingCode) && !string.IsNullOrEmpty(update.TrainingName)) { apprenticeship.TrainingCode = update.TrainingCode; apprenticeship.TrainingName = update.TrainingName; } apprenticeship.DateOfBirth = update.DateOfBirth ?? apprenticeship.DateOfBirth; apprenticeship.StartDate = update.StartDate ?? apprenticeship.StartDate; apprenticeship.EndDate = update.EndDate ?? apprenticeship.EndDate; UpdatePrice(apprenticeship, update); }
public void UpdateAllFields() { var dob = DateTime.Now.AddYears(19); var startDate = DateTime.Now.AddYears(2); var endDate = DateTime.Now.AddYears(4); var update = new ApprenticeshipUpdate { FirstName = "New First name", LastName = "New Last name", DateOfBirth = dob, TrainingType = TrainingType.Framework, TrainingCode = "training-code", TrainingName = "Training name", Cost = 1500, StartDate = startDate, EndDate = endDate }; _sut.ApplyUpdate(_apprenticeship, update); _apprenticeship.FirstName.Should().Be("New First name"); _apprenticeship.LastName.Should().Be("New Last name"); _apprenticeship.DateOfBirth.Should().Be(dob); _apprenticeship.TrainingType.Should().Be(TrainingType.Framework); _apprenticeship.TrainingCode.Should().Be("training-code"); _apprenticeship.TrainingName.Should().Be("Training name"); _apprenticeship.StartDate.Should().Be(startDate); _apprenticeship.EndDate.Should().Be(endDate); _apprenticeship.Cost.Should().Be(1500); EnsureNoOtherChanges(); }
public ApprenticeshipUpdate MapApprenticeshipUpdate(Types.Apprenticeship.ApprenticeshipUpdate update) { var result = new ApprenticeshipUpdate { Id = update.Id, ApprenticeshipId = update.ApprenticeshipId, Originator = (Originator)update.Originator, FirstName = update.FirstName, LastName = update.LastName, DateOfBirth = update.DateOfBirth, TrainingCode = update.TrainingCode, TrainingType = update.TrainingType.HasValue ? (TrainingType)update.TrainingType : default(TrainingType?), TrainingName = update.TrainingName, Cost = update.Cost, StartDate = update.StartDate, EndDate = update.EndDate, UpdateOrigin = (UpdateOrigin)update.UpdateOrigin, EffectiveFromDate = update.EffectiveFromDate, EffectiveToDate = null, ULN = update.ULN, ProviderRef = update.ProviderRef, EmployerRef = update.EmployerRef }; // Update the effective from date if they've made a change to the Start Date value - can only be done when waiting to start. if (update.StartDate.HasValue) { result.EffectiveFromDate = update.StartDate.Value; } return(result); }
private async Task CheckOverlappingApprenticeships(ApprenticeshipUpdate pendingUpdate, Apprenticeship originalApprenticeship) { if (originalApprenticeship.StartDate == null) { throw new InvalidOperationException($"The start date on apprenticeship {originalApprenticeship.Id} is null when calling {nameof(CheckOverlappingApprenticeships)}"); } if (originalApprenticeship.EndDate == null) { throw new InvalidOperationException($"The end date on apprenticeship {originalApprenticeship.Id} is null when calling {nameof(CheckOverlappingApprenticeships)}"); } var overlapResult = await _mediator.SendAsync(new GetOverlappingApprenticeshipsRequest { OverlappingApprenticeshipRequests = new List <ApprenticeshipOverlapValidationRequest> { new ApprenticeshipOverlapValidationRequest { ApprenticeshipId = originalApprenticeship.Id, Uln = originalApprenticeship.ULN, StartDate = pendingUpdate.StartDate ?? originalApprenticeship.StartDate.Value, EndDate = pendingUpdate.EndDate ?? originalApprenticeship.EndDate.Value } } }); if (overlapResult.Data.Any()) { throw new ValidationException("Unable to create ApprenticeshipUpdate due to overlapping apprenticeship"); } }
public void ShouldNotAllowChangesToStartDateWhenMoreThanOnePriceHistory() { _currentTime.Setup(m => m.Now).Returns(new DateTime(_yearNow, 05, 23)); _apprenticeship.PriceHistory = new List <PriceHistory> { new PriceHistory { FromDate = new DateTime(_yearNow, 01, 01), ToDate = new DateTime(_yearNow, 03, 31), Cost = 1199, ApprenticeshipId = 55 }, new PriceHistory { FromDate = new DateTime(_yearNow, 04, 01), ToDate = new DateTime(_yearNow, 06, 30), Cost = 2299, ApprenticeshipId = 55 }, new PriceHistory { FromDate = new DateTime(_yearNow, 07, 01), Cost = 3399, ApprenticeshipId = 55 } }; var update = new ApprenticeshipUpdate { Cost = 32333, StartDate = new DateTime(_yearNow, 08, 01) }; Action act = () => _sut.ApplyUpdate(_apprenticeship, update); act.ShouldThrow <InvalidOperationException>().Which.Message.Should().Be("Multiple Prices History Items not expected."); }
public void UpdateCostWhenSinglePriceHistory() { var update = new ApprenticeshipUpdate { Cost = 32333 }; _sut.ApplyUpdate(_apprenticeship, update); _apprenticeship.PriceHistory.Single().Cost.Should().Be(32333); }
public void EmptyUpdate() { var update = new ApprenticeshipUpdate(); _sut.ApplyUpdate(_apprenticeship, update); _apprenticeship.FirstName.Should().Be("Original First name"); _apprenticeship.LastName.Should().Be("Original Last name"); _apprenticeship.DateOfBirth.Should().Be(new DateTime(1998, 12, 8)); EnsureNoOtherChanges(); }
public void NameUpdate() { var update = new ApprenticeshipUpdate { FirstName = "New First name", LastName = "New Last name" }; _sut.ApplyUpdate(_apprenticeship, update); _apprenticeship.FirstName.Should().Be("New First name"); _apprenticeship.LastName.Should().Be("New Last name"); _apprenticeship.DateOfBirth.Should().Be(new DateTime(1998, 12, 8)); EnsureNoOtherChanges(); }
public async Task UndoApprenticeshipUpdate(ApprenticeshipUpdate apprenticeshipUpdate, string userId) { await WithTransaction(async (connection, trans) => { await UpdateApprenticeshipUpdate(connection, trans, apprenticeshipUpdate.Id, userId, ApprenticeshipUpdateStatus.Deleted); if (apprenticeshipUpdate.UpdateOrigin == UpdateOrigin.DataLock) { await ResetDatalockTriage(connection, trans, apprenticeshipUpdate.Id); } return(1L); }); }
private void ValidateCommand(RejectApprenticeshipChangeCommand command, ApprenticeshipUpdate pendingUpdate, Apprenticeship apprenticeship) { var result = _validator.Validate(command); if (!result.IsValid) { throw new ValidationException("Did not validate"); } if (pendingUpdate == null) { throw new ValidationException($"No existing apprenticeship update pending for apprenticeship {command.ApprenticeshipId}"); } CheckAuthorisation(command, apprenticeship); }
private static void AssertEquality(ApprenticeshipUpdate source, GetApprenticeshipUpdateQueryResult.ApprenticeshipUpdate result) { Assert.AreEqual(source.Id, result.Id); Assert.AreEqual(source.ApprenticeshipId, result.ApprenticeshipId); Assert.AreEqual(source.Originator, result.Originator); Assert.AreEqual(source.FirstName, result.FirstName); Assert.AreEqual(source.LastName, result.LastName); Assert.AreEqual(source.TrainingType, result.TrainingType); Assert.AreEqual(source.TrainingCode, result.TrainingCode); Assert.AreEqual(source.TrainingName, result.TrainingName); Assert.AreEqual(source.Cost, result.Cost); Assert.AreEqual(source.StartDate, result.StartDate); Assert.AreEqual(source.EndDate, result.EndDate); Assert.AreEqual(source.DateOfBirth, result.DateOfBirth); }
public async Task RejectApprenticeshipUpdate(ApprenticeshipUpdate apprenticeshipUpdate) { await WithTransaction(async (connection, trans) => { // this also sets PendingUpdateOriginator to null in apprenticeship await UpdateApprenticeshipUpdate(connection, trans, apprenticeshipUpdate.Id, ApprenticeshipUpdateStatus.Rejected); if (apprenticeshipUpdate.UpdateOrigin == UpdateOrigin.DataLock) { await ResetDatalockTriage(connection, trans, apprenticeshipUpdate.Id); } return(1L); }); }
public UpdateApprenticeshipViewModel MapFrom(ApprenticeshipUpdate apprenticeshipUpdate) { return(new UpdateApprenticeshipViewModel { Cost = NullableDecimalToString(apprenticeshipUpdate.Cost), DateOfBirth = new DateTimeViewModel(apprenticeshipUpdate.DateOfBirth), FirstName = apprenticeshipUpdate.FirstName, LastName = apprenticeshipUpdate.LastName, StartDate = new DateTimeViewModel(apprenticeshipUpdate.StartDate), EndDate = new DateTimeViewModel(apprenticeshipUpdate.EndDate), TrainingName = apprenticeshipUpdate.TrainingName, TrainingCode = apprenticeshipUpdate.TrainingCode, TrainingType = apprenticeshipUpdate.TrainingType, EmployerRef = apprenticeshipUpdate.EmployerRef }); }
protected override async Task HandleCore(CreateApprenticeshipUpdateCommand command) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } if (await _apprenticeshipUpdateRepository.GetPendingApprenticeshipUpdate(command.ApprenticeshipUpdate.ApprenticeshipId) != null) { throw new ValidationException("Unable to create an ApprenticeshipUpdate for an Apprenticeship with a pending update"); } var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipUpdate.ApprenticeshipId); if (!ValidateStartedApprenticeship(apprenticeship, command.ApprenticeshipUpdate)) { throw new ValidationException("Unable to create an update for an apprenticeship that is already started "); } CheckAuthorisation(command, apprenticeship); await CheckOverlappingApprenticeships(command, apprenticeship); Apprenticeship immediateUpdate = null; ApprenticeshipUpdate pendingUpdate = null; if (HasImmediateUpdate(command)) { await StartHistoryTracking(apprenticeship, command.Caller.CallerType, command.UserId, command.UserName); MapImmediateApprenticeshipUpdate(apprenticeship, command); immediateUpdate = apprenticeship; } if (command.ApprenticeshipUpdate.HasChanges) { pendingUpdate = command.ApprenticeshipUpdate; pendingUpdate.EffectiveFromDate = apprenticeship.StartDate.Value; } await Task.WhenAll( _apprenticeshipUpdateRepository.CreateApprenticeshipUpdate(pendingUpdate, immediateUpdate), SaveHistory() ); }
public async Task CreateApprenticeshipUpdate(ApprenticeshipUpdate apprenticeshipUpdate, Apprenticeship apprenticeship) { await WithTransaction(async (connection, trans) => { if (apprenticeshipUpdate != null) { // this also sets PendingUpdateOriginator to null on apprenticeship await _apprenticeshipUpdateTransactions.CreateApprenticeshipUpdate(connection, trans, apprenticeshipUpdate); } if (apprenticeship != null) { await _apprenticeshipUpdateTransactions.UpdateApprenticeshipReferenceAndUln(connection, trans, apprenticeship); } return(0); }); }
public async Task ApproveApprenticeshipUpdate(ApprenticeshipUpdate apprenticeshipUpdate, string userId, Apprenticeship apprenticeship, Caller caller) { await WithTransaction(async (connection, trans) => { await _apprenticeshipTransactions.UpdateApprenticeship(connection, trans, apprenticeship, caller); await _apprenticeshipTransactions.UpdateCurrentPrice(connection, trans, apprenticeship); await UpdateApprenticeshipUpdate(connection, trans, apprenticeshipUpdate.Id, userId, ApprenticeshipUpdateStatus.Approved); if (apprenticeshipUpdate.UpdateOrigin == UpdateOrigin.DataLock) { await ResolveDatalock(connection, trans, apprenticeshipUpdate.Id); } return(1L); }); }
private Task ValidateCommand(AcceptApprenticeshipChangeCommand command, ApprenticeshipUpdate pendingUpdate, Apprenticeship apprenticeship) { var result = _validator.Validate(command); if (!result.IsValid) { throw new ValidationException("Did not validate"); } if (pendingUpdate == null) { throw new ValidationException($"No existing apprenticeship update pending for apprenticeship {command.ApprenticeshipId}"); } CheckAuthorisation(command, apprenticeship); return(CheckOverlappingApprenticeships(pendingUpdate, apprenticeship)); }
public async Task CreateApprenticeshipUpdate(ApprenticeshipUpdate apprenticeshipUpdate, Apprenticeship apprenticeship) { await WithTransaction(async (connection, trans) => { if (apprenticeshipUpdate != null) { await _apprenticeshipUpdateTransactions.CreateApprenticeshipUpdate(connection, trans, apprenticeshipUpdate); } if (apprenticeship != null) { await _apprenticeshipUpdateTransactions.UpdateApprenticeshipReferenceAndUln(connection, trans, apprenticeship); } return(0); }); }
private bool ValidateStartedApprenticeship(Apprenticeship apprenticeship, ApprenticeshipUpdate apprenticeshipUpdate) { var started = apprenticeship.StartDate.HasValue && apprenticeship.StartDate.Value <= new DateTime(_currentDateTime.Now.Year, _currentDateTime.Now.Month, 1); if (!started) { return(true); } if (apprenticeship.HasHadDataLockSuccess && (apprenticeshipUpdate.Cost != null || apprenticeshipUpdate.TrainingCode != null) ) { _logger.Warn($"Trying to update a started apprenticeship with a successful DataLock with values; Cost {apprenticeshipUpdate.Cost}, TrainingCode: {apprenticeshipUpdate.TrainingCode}"); return(false); } return(true); }
private async Task CheckOverlappingApprenticeships(ApprenticeshipUpdate pendingUpdate, Apprenticeship originalApprenticeship) { var overlapResult = await _mediator.SendAsync(new GetOverlappingApprenticeshipsRequest { OverlappingApprenticeshipRequests = new List <ApprenticeshipOverlapValidationRequest> { new ApprenticeshipOverlapValidationRequest { ApprenticeshipId = originalApprenticeship.Id, Uln = originalApprenticeship.ULN, StartDate = pendingUpdate.StartDate ?? originalApprenticeship.StartDate.Value, EndDate = pendingUpdate.EndDate ?? originalApprenticeship.EndDate.Value } } }); if (overlapResult.Data.Any()) { throw new ValidationException("Unable to create ApprenticeshipUpdate due to overlapping apprenticeship"); } }
public void ShouldUpdateStartDateOnPriceHistory() { _currentTime.Setup(m => m.Now).Returns(new DateTime(_yearNow, 05, 23)); _apprenticeship.PriceHistory = new List <PriceHistory> { new PriceHistory { FromDate = new DateTime(_yearNow, 01, 01), Cost = 3399, ApprenticeshipId = 55 } }; var newStartDate = new DateTime(_yearNow, 08, 01); var update = new ApprenticeshipUpdate { Cost = 32333, StartDate = newStartDate }; _sut.ApplyUpdate(_apprenticeship, update); _apprenticeship.PriceHistory[0].Cost.ShouldBeEquivalentTo(32333); _apprenticeship.PriceHistory[0].FromDate.ToString("O").ShouldBeEquivalentTo(newStartDate.ToString("O")); }
public void Arrange() { _validator = new Mock <GetPendingApprenticeshipUpdateValidator>(); _validator.Setup(x => x.Validate(It.IsAny <GetPendingApprenticeshipUpdateRequest>())) .Returns(() => new ValidationResult()); var testApprenticeship = new Apprenticeship { Id = 999, EmployerAccountId = 888, ProviderId = 777 }; _testRecord = new ApprenticeshipUpdate { Id = 1, ApprenticeshipId = 1, Originator = Originator.Employer, FirstName = "John", LastName = "Smith", DateOfBirth = new DateTime(2000, 01, 03), TrainingType = TrainingType.Framework, TrainingCode = "AB-123", TrainingName = "Test Course", Cost = 1000, StartDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2018, 6, 1) }; _apprenticeshipRepository = new Mock <IApprenticeshipRepository>(); _apprenticeshipRepository.Setup(x => x.GetApprenticeship(It.IsAny <long>())) .ReturnsAsync(testApprenticeship); _apprenticeshipUpdateRepository = new Mock <IApprenticeshipUpdateRepository>(); _apprenticeshipUpdateRepository.Setup(x => x.GetPendingApprenticeshipUpdate(It.IsAny <long>())) .ReturnsAsync(_testRecord); _handler = new GetPendingApprenticeshipUpdateQueryHandler(_validator.Object, _apprenticeshipUpdateRepository.Object, _apprenticeshipRepository.Object); }
public void ThenAllChangedFieldsAreMapped() { //Arrange var original = new Apprenticeship(); var update = new ApprenticeshipUpdate { ApprenticeshipId = 1, FirstName = "FirstName", LastName = "LastName", DateOfBirth = new DateTime(2000, 1, 1), ULN = "2222222222", TrainingType = TrainingType.Framework, TrainingName = "TrainingName", TrainingCode = "TrainingCode", Cost = 1000, StartDate = new DateTime(2020, 1, 1), EndDate = new DateTime(2021, 1, 1), ProviderRef = "ProviderRef", EmployerRef = "EmployerRef" }; var result = _mapper.MapApprenticeshipUpdateViewModel <ApprenticeshipUpdateViewModel>(original, update); Assert.AreEqual("hashed", result.HashedApprenticeshipId); Assert.AreEqual("FirstName", result.FirstName); Assert.AreEqual("LastName", result.LastName); Assert.AreEqual(new DateTime(2000, 1, 1), result.DateOfBirth.DateTime); Assert.AreEqual("2222222222", result.ULN); Assert.AreEqual(Domain.TrainingType.Framework, result.CourseType); Assert.AreEqual("TrainingName", result.CourseName); Assert.AreEqual("TrainingCode", result.CourseCode); Assert.AreEqual("1000", result.Cost); Assert.AreEqual(new DateTime(2020, 1, 1), result.StartDate.DateTime); Assert.AreEqual(new DateTime(2021, 1, 1), result.EndDate.DateTime); Assert.AreEqual("ProviderRef", result.ProviderRef); Assert.AreEqual("EmployerRef", result.EmployerRef); Assert.AreEqual(original, result.OriginalApprenticeship); }
public async Task ShouldCallMediatorToCreate() { var providerId = 123; string userId = "ABC"; var expectedApprenticeship = new ApprenticeshipUpdate(); var viewModel = new CreateApprenticeshipUpdateViewModel(); var signedInUser = new SignInUserModel() { DisplayName = "Bob", Email = "*****@*****.**" }; _mockApprenticeshipMapper.Setup(x => x.MapApprenticeshipUpdate(viewModel)).Returns(expectedApprenticeship); await _orchestrator.CreateApprenticeshipUpdate(viewModel, providerId, userId, signedInUser); _mockMediator.Verify( x => x.Send( It.Is <CreateApprenticeshipUpdateCommand>( c => c.ProviderId == providerId && c.UserId == userId && c.ApprenticeshipUpdate == expectedApprenticeship && c.UserDisplayName == signedInUser.DisplayName && c.UserEmailAddress == signedInUser.Email), It.IsAny <CancellationToken>()), Times.Once); }
private void UpdatePrice(Apprenticeship apprenticeship, ApprenticeshipUpdate update) { if (update.Cost.HasValue) { if (apprenticeship.PriceHistory.Count != 1) { throw new InvalidOperationException("Multiple Prices History Items not expected."); } apprenticeship.Cost = update.Cost.Value; apprenticeship.PriceHistory[0].Cost = update.Cost.Value; } if (update.StartDate.HasValue) { if (apprenticeship.PriceHistory.Count != 1) { throw new InvalidOperationException("Multiple Prices History Items not expected."); } apprenticeship.PriceHistory[0].FromDate = update.StartDate ?? apprenticeship.PriceHistory.Single().FromDate; } }
private async Task CheckReservation(ApprenticeshipUpdate pendingUpdate, Apprenticeship originalApprenticeship) { var request = new ReservationValidationServiceRequest { AccountId = originalApprenticeship.EmployerAccountId, ApprenticeshipId = originalApprenticeship.Id, ReservationId = originalApprenticeship.ReservationId, CommitmentId = originalApprenticeship.CommitmentId, TrainingCode = pendingUpdate.TrainingCode ?? originalApprenticeship.TrainingCode, StartDate = pendingUpdate.StartDate ?? originalApprenticeship.StartDate, ProviderId = originalApprenticeship.ProviderId }; var validationResult = await _reservationValidationService.CheckReservation(request); if (validationResult.HasErrors) { var validationFailures = validationResult.ValidationErrors.Select(e => new ValidationFailure(e.PropertyName, e.Reason)); throw new ValidationException(validationFailures); } }
public ViewApprenticeshipUpdatesRequestToViewModelMapperTestsFixture() { var autoFixture = new Fixture(); autoFixture.Customizations.Add(new DateTimeSpecimenBuilder()); CommitmentApiClient = new Mock <ICommitmentsApiClient>(); Source = new ViewApprenticeshipUpdatesRequest { ApprenticeshipId = ApprenticeshipId, ProviderId = 22, ApprenticeshipHashedId = "XXX" }; GetApprenticeshipResponse = autoFixture.Create <GetApprenticeshipResponse>(); GetApprenticeshipResponse.Id = ApprenticeshipId; autoFixture.RepeatCount = 1; GetApprenticeshipUpdatesResponses = autoFixture.Create <GetApprenticeshipUpdatesResponse>(); ApprenticeshipUpdate = GetApprenticeshipUpdatesResponses.ApprenticeshipUpdates.First(); GetTrainingProgrammeResponse = autoFixture.Create <GetTrainingProgrammeResponse>(); var priceEpisode = new GetPriceEpisodesResponse { PriceEpisodes = new List <GetPriceEpisodesResponse.PriceEpisode>() { new GetPriceEpisodesResponse.PriceEpisode { FromDate = DateTime.UtcNow.AddDays(-10), ToDate = null, Cost = 100 } } }; CommitmentApiClient.Setup(x => x.GetApprenticeship(ApprenticeshipId, It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetApprenticeshipResponse)); CommitmentApiClient.Setup(x => x.GetApprenticeshipUpdates(ApprenticeshipId, It.IsAny <GetApprenticeshipUpdatesRequest>(), It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetApprenticeshipUpdatesResponses)); CommitmentApiClient.Setup(x => x.GetPriceEpisodes(ApprenticeshipId, It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(priceEpisode)); CommitmentApiClient.Setup(x => x.GetTrainingProgramme(It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(GetTrainingProgrammeResponse)); Mapper = new ViewApprenticeshipUpdatesRequestToViewModelMapper(CommitmentApiClient.Object); }
public Types.Apprenticeship.ApprenticeshipUpdate MapApprenticeshipUpdate(ApprenticeshipUpdate data) { if (data == null) { return(null); } return(new Types.Apprenticeship.ApprenticeshipUpdate { Id = data.Id, ApprenticeshipId = data.ApprenticeshipId, Originator = (Types.Apprenticeship.Types.Originator)data.Originator, FirstName = data.FirstName, LastName = data.LastName, DateOfBirth = data.DateOfBirth, TrainingCode = data.TrainingCode, TrainingType = data.TrainingType.HasValue ? (Types.Apprenticeship.Types.TrainingType)data.TrainingType : default(Types.Apprenticeship.Types.TrainingType?), TrainingName = data.TrainingName, Cost = data.Cost, StartDate = data.StartDate, EndDate = data.EndDate }); }
public T MapApprenticeshipUpdateViewModel <T>(Apprenticeship original, ApprenticeshipUpdate update) where T : ApprenticeshipUpdateViewModel, new() { return(new T { HashedApprenticeshipId = _hashingService.HashValue(update.ApprenticeshipId), FirstName = update.FirstName, LastName = update.LastName, DateOfBirth = new DateTimeViewModel(update.DateOfBirth), ULN = update.ULN, CourseType = update.TrainingType.HasValue ? (TrainingType)update.TrainingType.Value : default(TrainingType?), CourseCode = update.TrainingCode, CourseName = update.TrainingName, Cost = update.Cost.HasValue ? update.Cost.ToString() : string.Empty, StartDate = new DateTimeViewModel(update.StartDate), EndDate = new DateTimeViewModel(update.EndDate), ProviderRef = update.ProviderRef, EmployerRef = update.EmployerRef, OriginalApprenticeship = original, LegalEntityName = original.LegalEntityName, ProviderName = original.ProviderName }); }
public async Task <long> CreateApprenticeshipUpdate(IDbConnection connection, IDbTransaction trans, ApprenticeshipUpdate apprenticeshipUpdate) { var parameters = new DynamicParameters(); parameters.Add("@apprenticeshipId", apprenticeshipUpdate.ApprenticeshipId); parameters.Add("@Originator", apprenticeshipUpdate.Originator); parameters.Add("@FirstName", apprenticeshipUpdate.FirstName); parameters.Add("@LastName", apprenticeshipUpdate.LastName); parameters.Add("@TrainingType", apprenticeshipUpdate.TrainingType); parameters.Add("@TrainingCode", apprenticeshipUpdate.TrainingCode); parameters.Add("@TrainingName", apprenticeshipUpdate.TrainingName); parameters.Add("@Cost", apprenticeshipUpdate.Cost); parameters.Add("@StartDate", apprenticeshipUpdate.StartDate); parameters.Add("@EndDate", apprenticeshipUpdate.EndDate); parameters.Add("@DateOfBirth", apprenticeshipUpdate.DateOfBirth); parameters.Add("@CreatedOn", _currentDateTime.Now); parameters.Add("@UpdateOrigin", apprenticeshipUpdate.UpdateOrigin); parameters.Add("@EffectiveFromDate", apprenticeshipUpdate.EffectiveFromDate); parameters.Add("@EffectiveToDate", apprenticeshipUpdate.EffectiveToDate); return((await connection.QueryAsync <long>( sql: $"[dbo].[CreateApprenticeshipUpdate]", param: parameters, transaction: trans, commandType: CommandType.StoredProcedure)).Single()); }