コード例 #1
0
        public async void Handle_CouldNotCreateOrganisationResearcher_Test()
        {
            Organisation organisation = new Organisation()
            {
            };

            this._unitOfUnitMock.Setup(mock => mock.OrganisationRepository.Create(It.IsAny <Organisation>()))
            .Returns(organisation);

            OrganisationResearcher nullItem = null;

            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationResearcher(It.IsAny <OrganisationResearcher>()))
            .Returns(nullItem);

            CreateOrganisationCommand command = new CreateOrganisationCommand(new OrganisationWithChildren()
            {
                Created            = DateTime.Now,
                OrganisationName   = "s",
                Address            = "s",
                MainOrganisationId = 1,
                ZipCode            = "6700",
                City        = "es",
                Country     = "sad",
                Researchers = new List <ResearcherModel>()
                {
                    new ResearcherModel()
                }
            });

            var handler = new CreateOrganisationHandler(this._unitOfUnitMock.Object);
            var result  = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Null(result);
        }
コード例 #2
0
        public async Task <IActionResult> CreateOrganisation([FromBody] OrganisationWithChildren organisation)
        {
            if (organisation == null)
            {
                return(new BadRequestObjectResult("Invalid Model"));
            }

            var command = new CreateOrganisationCommand(organisation);

            var result = await this._mediator.Send(command);

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult(result));
        }
コード例 #3
0
        public CreateOrganisationCommand Map(CreateOrganisationRequest request)
        {
            int      organisationStatusId;
            DateTime?startDate = null;

            switch (request.ProviderTypeId)
            {
            case ProviderType.MainProvider:
            case ProviderType.EmployerProvider:
                organisationStatusId = OrganisationStatus.Onboarding;
                break;

            case ProviderType.SupportingProvider:
                organisationStatusId = OrganisationStatus.Active;
                startDate            = DateTime.Today;
                break;

            default:
                throw new Exception($"Provider Type {request.ProviderTypeId} not recognised");
            }

            var command = new CreateOrganisationCommand
            {
                CharityNumber          = request.CharityNumber,
                CompanyNumber          = request.CompanyNumber,
                FinancialTrackRecord   = request.FinancialTrackRecord,
                LegalName              = request.LegalName,
                NonLevyContract        = request.NonLevyContract,
                OrganisationStatusId   = organisationStatusId,
                OrganisationTypeId     = request.OrganisationTypeId,
                ParentCompanyGuarantee = request.ParentCompanyGuarantee,
                ProviderTypeId         = request.ProviderTypeId,
                StatusDate             = request.StatusDate,
                Ukprn                     = request.Ukprn,
                TradingName               = request.TradingName,
                StartDate                 = startDate,
                Username                  = request.Username,
                SourceIsUKRLP             = request.SourceIsUKRLP,
                ApplicationDeterminedDate = request.ApplicationDeterminedDate
            };

            return(command);
        }
コード例 #4
0
        public void Organisation_is_created_and_start_date_is_correct()
        {
            const long organisationUkprn = 12344321;

            var command = new CreateOrganisationCommand
            {
                Ukprn = organisationUkprn,
                OrganisationTypeId   = _organisationTypeId1,
                ProviderTypeId       = _providerTypeId1,
                OrganisationStatusId = _organisationStatusId1,
                StatusDate           = DateTime.Today.AddDays(5),
                LegalName            = "Legal McLegal",
                Username             = "******",
                StartDate            = DateTime.Today
            };

            var orgPlaceholder = _repository.CreateOrganisation(command).Result;

            var organisationDetails = OrganisationHandler.GetOrganisationFromukprn(organisationUkprn);
            var organisationData    = new OrganisationDataHandler().Parse(organisationDetails.OrganisationData);

            Assert.AreEqual(DateTime.Today, organisationData.StartDate);
        }
コード例 #5
0
        public async Task <Guid?> CreateOrganisation(CreateOrganisationCommand command)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                var startDate          = command.StartDate;
                var organisationId     = Guid.NewGuid();
                var createdAt          = DateTime.Now;
                var createdBy          = command.Username;
                var providerTypeId     = command.ProviderTypeId;
                var organisationTypeId = command.OrganisationTypeId;
                var statusId           = command.OrganisationStatusId;
                var organisationData   = new OrganisationData
                {
                    CompanyNumber          = command.CompanyNumber?.ToUpper(),
                    CharityNumber          = command.CharityNumber,
                    ParentCompanyGuarantee = command.ParentCompanyGuarantee,
                    FinancialTrackRecord   = command.FinancialTrackRecord,
                    NonLevyContract        = command.NonLevyContract,
                    StartDate                 = startDate,
                    SourceIsUKRLP             = command.SourceIsUKRLP,
                    ApplicationDeterminedDate = command.ApplicationDeterminedDate
                };

                string sql = $"INSERT INTO [dbo].[Organisations] " +
                             " ([Id] " +
                             ",[CreatedAt] " +
                             ",[CreatedBy] " +
                             ",[StatusId] " +
                             ",[ProviderTypeId] " +
                             ",[OrganisationTypeId] " +
                             ",[UKPRN] " +
                             ",[LegalName] " +
                             ",[TradingName] " +
                             ",[StatusDate] " +
                             ",[OrganisationData]) " +
                             "VALUES " +
                             "(@organisationId, @createdAt, @createdBy, @statusId, @providerTypeId, @organisationTypeId," +
                             " @ukprn, @legalName, @tradingName, @statusDate, @organisationData)";

                var organisationsCreated = await connection.ExecuteAsync(sql,
                                                                         new
                {
                    organisationId,
                    createdAt,
                    createdBy,
                    statusId,
                    providerTypeId,
                    organisationTypeId,
                    command.Ukprn,
                    command.LegalName,
                    command.TradingName,
                    command.StatusDate,
                    organisationData
                });

                var success = await Task.FromResult(organisationsCreated > 0);

                if (success)
                {
                    return(organisationId);
                }

                return(null);
            }
        }