public void UpdateStatus(AdminLicenceViewModel model) { var statusChange = repository.Create <LicenceStatusChange>(); statusChange.Licence = repository.GetById <Licence>(model.Licence.Id); statusChange.DateCreated = dateTimeProvider.Now(); statusChange.Status = repository.GetById <LicenceStatus>(model.NewLicenceStatus); statusChange.Reason = repository.GetById <StatusReason>(model.NewStatusReason); statusChange.NonCompliantStandards = model.Standards.Where(x => x.Checked) .Select(y => repository.GetById <LicenceStatusChangeLicensingStandard>(y.Id)).ToList(); statusChange.Licence.CurrentStatusChange = statusChange; repository.Upsert(statusChange.Licence); }
public AdminStatusLicencesViewModel Build(int id) { return(new AdminStatusLicencesViewModel { LicenceApplicationViewModels = GetLicencesByStatus(id).ToList(), LicenceStatusViewModel = _mapper.Map <LicenceStatusViewModel>(_repository.GetById <LicenceStatus>(id)), Countries = _referenceDataProvider.GetCountries() }); }
public void it_should_create_new_licence_and_address_entities_and_return_the_licence_id() { const int expectedId = 1; var licence = new Licence { Id = 1 }; repository.Create <Licence>().Returns(licence); repository.Create <Address>().Returns(new Address()); repository.Upsert(Arg.Any <Licence>()).ReturnsForAnyArgs(1); repository.GetById <Licence>(expectedId).Returns(licence); var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider); var result = pdh.Insert(new LicenceApplicationViewModel()); Assert.AreEqual(expectedId, result); repository.Received().Create <Licence>(); repository.Received().Create <Address>(); }
/// <summary> /// Create or update a restraint order and link it to the principal authority /// </summary> /// <param name="paId">The ID of the PA</param> /// <param name="roId">The ID of the ro if it exists</param> /// <param name="model">The model to update from</param> /// <returns>The ID of the RO</returns> public int UpsertRestraintOrderAndLinkToPrincipalAuthority(int paId, int roId, RestraintOrdersViewModel model) { var pa = repository.GetById <PrincipalAuthority>(paId); RestraintOrder ro; if (pa.RestraintOrders.None(r => r.Id == roId)) { ro = repository.Create <RestraintOrder>(); ro.PrincipalAuthority = pa; } else { ro = pa.RestraintOrders.Single(r => r.Id == roId); } this.mapper.Map(model, ro); return(repository.Upsert(ro)); }
public void it_should_add_checked_items_to_the_entity_from_the_model() { const int expectedId = 1; const string expectedName = "Name"; var licence = new Licence { Id = expectedId, OperatingIndustries = new List <LicenceIndustry>() }; var model = new OperatingIndustriesViewModel { OperatingIndustries = new List <CheckboxListItem> { new CheckboxListItem { Id = expectedId, Name = expectedName, Checked = true } } }; licenceRepository.GetById(expectedId).Returns(licence); repository.GetById <Industry>(expectedId).Returns(new Industry { Id = expectedId, Name = expectedName }); var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider); pdh.Update(expectedId, l => l.OperatingIndustries, model.OperatingIndustries); repository.Received(1).Upsert(Arg.Is <Licence>(l => l.OperatingIndustries.Single().Id == expectedId && l.OperatingIndustries.Single().IndustryId == expectedId && l.OperatingIndustries.Single().LicenceId == expectedId)); }
public void it_updates_a_principal_authority_and_creates_a_link_to_the_director() { const int licenceId = 1; const int paId = 2; const int dopId = 3; const string expectedName = "Name"; var licence = new Licence { Id = licenceId, PrincipalAuthorities = new List <PrincipalAuthority> { new PrincipalAuthority { Id = paId, DirectorOrPartner = null } } }; var model = new FullNameViewModel { FullName = expectedName }; licenceRepository.GetById(licenceId).Returns(licence); repository.GetById <DirectorOrPartner>(dopId).Returns(new DirectorOrPartner { Id = dopId }); repository.Upsert(Arg.Any <PrincipalAuthority>()).Returns(paId); var pdh = new LicenceApplicationPostDataHandler(mapper, repository, licenceRepository, statusRepository, dateTimeProvider); var result = pdh.UpsertPrincipalAuthorityAndLinkToDirectorOrPartner(licenceId, dopId, paId, model); Assert.AreEqual(paId, result); repository.Received(1).Upsert(Arg.Is <PrincipalAuthority>(p => p.FullName.Equals(expectedName) && p.DirectorOrPartner.Id == dopId)); repository.Received(0).Create <PrincipalAuthority>(); repository.Received(1).GetById <DirectorOrPartner>(dopId); }