コード例 #1
0
        public async Task <string> UpdateEpaOrganisationContact(EpaContact contact, string actionChoice)
        {
            await _unitOfWork.Connection.ExecuteAsync(
                "UPDATE [Contacts] SET [DisplayName] = @displayName, [Email] = @email, " +
                "[GivenNames] = @firstName, [FamilyName] = @lastName, " +
                "[PhoneNumber] = @phoneNumber, [updatedAt] = getUtcDate() " +
                "WHERE [Id] = @Id ",
                new
            {
                contact.DisplayName,
                contact.Email,
                firstName = string.IsNullOrEmpty(contact.FirstName) ? " " : contact.FirstName,
                lastName  = string.IsNullOrEmpty(contact.LastName) ? " " : contact.LastName,
                contact.PhoneNumber,
                contact.Id
            });

            if (actionChoice == "MakePrimaryContact")
            {
                await _unitOfWork.Connection.ExecuteAsync(
                    "update o set PrimaryContact = c.Username from organisations o " +
                    "inner join contacts c on o.EndPointAssessorOrganisationId = c.EndPointAssessorOrganisationId " +
                    "Where c.id = @Id",
                    new { contact.Id });
            }

            return(contact.Id.ToString());
        }
        public void Setup()
        {
            _registerRepository = new Mock <IRegisterRepository>();
            _cleanserService    = new Mock <ISpecialCharacterCleanserService>();
            _validator          = new Mock <IEpaOrganisationValidator>();
            _logger             = new Mock <ILogger <UpdateEpaOrganisationContactHandler> >();
            _contactId          = Guid.NewGuid().ToString();
            _email       = "*****@*****.**";
            _firstName   = "Joe";
            _lastName    = "Cool";
            _phoneNumber = "555 4444";

            _requestNoIssues = BuildRequest(_contactId, _firstName, _lastName, _email, _phoneNumber);
            _expectedOrganisationContactNoIssues = BuildOrganisationStandard(_requestNoIssues);

            _registerRepository.Setup(r => r.UpdateEpaOrganisationContact(It.IsAny <EpaContact>(), It.IsAny <string>()))
            .Returns(Task.FromResult(_expectedOrganisationContactNoIssues.Id.ToString()));

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(It.IsAny <string>()))
            .Returns((string s) => s);

            _validator.Setup(v => v.ValidatorUpdateEpaOrganisationContactRequest(_requestNoIssues))
            .Returns(new ValidationResponse());

            _updateEpaOrganisationContactHandler = new UpdateEpaOrganisationContactHandler(_registerRepository.Object, _validator.Object, _cleanserService.Object, _logger.Object);
        }
コード例 #3
0
        public async Task <string> CreateEpaOrganisationContact(EpaContact contact)
        {
            await _unitOfWork.Connection.ExecuteAsync(
                $@"INSERT INTO [dbo].[Contacts] ([Id],[CreatedAt],[DisplayName],[Email],[EndPointAssessorOrganisationId],[OrganisationId],[Status],[Username],[PhoneNumber], [GivenNames], [FamilyName], [SigninId], [SigninType]) " +
                $@"VALUES (@id,getutcdate(), @displayName, @email, @endPointAssessorOrganisationId," +
                $@"(select id from organisations where EndPointAssessorOrganisationId=@endPointAssessorOrganisationId), " +
                $@"'Live', @username, @PhoneNumber, @FirstName, @LastName, @SigninId, @SigninType);",
                new
            {
                contact.Id,
                contact.DisplayName,
                contact.Email,
                contact.EndPointAssessorOrganisationId,
                contact.Username,
                contact.PhoneNumber,
                firstName = string.IsNullOrEmpty(contact.FirstName) ? " " : contact.FirstName,
                lastName  = string.IsNullOrEmpty(contact.LastName) ? " " : contact.LastName,
                contact.SigninId,
                contact.SigninType
            });

            await _unitOfWork.Connection.ExecuteAsync(
                "UPDATE [dbo].[Organisations] set PrimaryContact=@username WHERE EndPointAssessorOrganisationId = @endPointAssessorOrganisationId and PrimaryContact is null",
                new
            {
                contact.EndPointAssessorOrganisationId,
                contact.Username
            });

            return(contact.Id.ToString());
        }
コード例 #4
0
        public void SetUpOrganisationTests()
        {
            var databaseConnection = new SqlConnection(_databaseService.WebConfiguration.SqlConnectionString);
            var unitOfWork         = new UnitOfWork(databaseConnection);

            _repository           = new RegisterRepository(unitOfWork, new Mock <ILogger <RegisterRepository> >().Object);
            _validationRepository = new RegisterValidationRepository(unitOfWork);

            _organisationIdCreated = "EPA0987";
            _ukprnCreated          = 123321;
            _org2IdCreated         = "EPA0001";
            _organisationTypeId    = 5;
            OrganisationTypeHandler.InsertRecord(new OrganisationTypeModel {
                Id = _organisationTypeId, Status = "new", Type = "organisation type 1"
            });
            _id = Guid.NewGuid();

            _organisation = new OrganisationModel
            {
                Id                             = _id,
                CreatedAt                      = DateTime.Now,
                EndPointAssessorName           = "name 2",
                EndPointAssessorOrganisationId = _organisationIdCreated,
                EndPointAssessorUkprn          = _ukprnCreated,
                PrimaryContact                 = null,
                OrganisationTypeId             = _organisationTypeId,
                OrganisationData               = null,
                Status                         = OrganisationStatus.New
            };

            _organisation2 = new OrganisationModel
            {
                Id                             = Guid.NewGuid(),
                CreatedAt                      = DateTime.Now,
                EndPointAssessorName           = "name 1",
                EndPointAssessorOrganisationId = _org2IdCreated,
                OrganisationTypeId             = null,
                Status                         = OrganisationStatus.New
            };

            _username = "******";
            OrganisationHandler.InsertRecord(_organisation);
            OrganisationHandler.InsertRecord(_organisation2);

            _contactId = Guid.NewGuid();

            _contact = new EpaContact
            {
                Id = _contactId,
                EndPointAssessorOrganisationId = _organisationIdCreated,
                Username    = _username,
                DisplayName = "Joe Cool",
                Email       = "*****@*****.**",
                PhoneNumber = "555 55555",
                Status      = OrganisationStatus.New,
                SigninType  = "",
                FirstName   = "zzz",
                LastName    = "Ftagn"
            };
        }
コード例 #5
0
        public void Setup()
        {
            _registerRepository = new Mock <IRegisterRepository>();
            _cleanserService    = new Mock <ISpecialCharacterCleanserService>();
            _validator          = new Mock <IEpaOrganisationValidator>();
            _logger             = new Mock <ILogger <CreateEpaOrganisationContactHandler> >();
            _idGenerator        = new Mock <IEpaOrganisationIdGenerator>();
            _organisationId     = "EPA999";
            _firstName          = "Testy";
            _lastName           = "McTestFace";

            _email                               = "*****@*****.**";
            _phoneNumber                         = "555 5555";
            _requestNoIssuesUserName             = "******";
            _requestNoIssues                     = BuildRequest(_organisationId, _firstName, _lastName, _email, _phoneNumber);
            _expectedOrganisationContactNoIssues = BuildOrganisationContact(_requestNoIssues, _requestNoIssuesUserName);

            _registerRepository.Setup(r => r.CreateEpaOrganisationContact(It.IsAny <EpaContact>()))
            .Returns(Task.FromResult(_expectedOrganisationContactNoIssues.Username));

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(It.IsAny <string>()))
            .Returns((string s) => s);

            _validator.Setup(v => v.ValidatorCreateEpaOrganisationContactRequest(_requestNoIssues))
            .Returns(new ValidationResponse());
            _idGenerator.Setup(i => i.GetNextContactUsername()).Returns(_requestNoIssuesUserName);

            _createEpaOrganisationContactHandler = new CreateEpaOrganisationContactHandler(_registerRepository.Object, _validator.Object, _cleanserService.Object, _logger.Object, _idGenerator.Object);
        }
コード例 #6
0
        public async Task <string> AssociateAllPrivilegesWithContact(EpaContact contact)
        {
            await _unitOfWork.Connection.ExecuteAsync(
                @" insert into[ContactsPrivileges]" +
                @" select co1.id, pr1.id from Contacts co1 cross join[Privileges] pr1" +
                @"  where co1.status = 'Live'  and co1.username not like 'unknown%' and co1.username != 'manual' and co1.Id = @Id" +
                @"  AND NOT EXISTS(SELECT NULL FROM [ContactsPrivileges] WHERE ContactId = co1.id AND PrivilegeId = pr1.id)",
                new
            {
                contact.Id,
            });

            return(contact.Id.ToString());
        }
コード例 #7
0
        //Fix for ON-2047
        public async Task <string> AssociateDefaultPrivilegesWithContact(EpaContact contact)
        {
            await _unitOfWork.Connection.ExecuteAsync(
                @" INSERT INTO[ContactsPrivileges](contactid, PrivilegeId)" +
                @" SELECT contactid, PrivilegeId FROM (select co1.id contactid, pr1.id PrivilegeId from Contacts co1 cross join[Privileges] pr1" +
                @" where MustBeAtLeastOneUserAssigned = 1 and co1.username not like 'unknown%' and co1.username != 'manual' and co1.Id = @Id" +
                @" and co1.Status = 'Live') ab1" +
                @" WHERE NOT EXISTS(SELECT NULL FROM[ContactsPrivileges] WHERE ContactId = ab1.ContactId AND PrivilegeId = ab1.PrivilegeId)",
                new
            {
                contact.Id,
            });

            return(contact.Id.ToString());
        }
コード例 #8
0
        public async Task <string> AssociateAllPrivilegesWithContact(EpaContact contact)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                connection.Execute(
                    @" insert into[ContactsPrivileges]" +
                    @" select co1.id, pr1.id from Contacts co1 cross join[Privileges] pr1" +
                    @"  where co1.status = 'Live'  and co1.username not like 'unknown%' and co1.username != 'manual' and co1.Id = @Id" +
                    @"  AND NOT EXISTS(SELECT NULL FROM [ContactsPrivileges] WHERE ContactId = co1.id AND PrivilegeId = pr1.id)",
                    new
                {
                    contact.Id,
                });


                return(contact.Id.ToString());
            }
        }
コード例 #9
0
        public async Task <string> AssociateDefaultRoleWithContact(EpaContact contact)
        {
            using (var connection = new SqlConnection(_configuration.SqlConnectionString))
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                connection.Execute(
                    @"INSERT INTO[ContactRoles] SELECT ab1.*, co1.id contactid FROM( SELECT newid() Id, 'SuperUser' Rolename) ab1 CROSS JOIN[Contacts] co1 WHERE co1.[Status] = 'Live'" +
                    @" AND EXISTS(SELECT NULL FROM Organisations og1 WHERE og1.id = co1.OrganisationId AND og1.[Status] != 'Deleted')" +
                    @" AND NOT EXISTS(SELECT NULL FROM[ContactRoles] co2 WHERE co2.ContactId = @Id)" +
                    @" AND co1.Id = @Id",
                    new
                {
                    contact.Id,
                });


                return(contact.Id.ToString());
            }
        }
        public void SetUpOrganisationTests()
        {
            _repository            = new RegisterRepository(_databaseService.WebConfiguration, new Mock <ILogger <RegisterRepository> >().Object);
            _validationRepository  = new RegisterValidationRepository(_databaseService.WebConfiguration);
            _organisationIdCreated = "EPA0987";
            _organisationTypeId    = 5;
            OrganisationTypeHandler.InsertRecord(new OrganisationTypeModel {
                Id = _organisationTypeId, Status = "new", Type = "organisation type 1"
            });
            _id = Guid.NewGuid();

            _organisation = new OrganisationModel
            {
                Id                             = _id,
                CreatedAt                      = DateTime.Now,
                EndPointAssessorName           = "name 2",
                EndPointAssessorOrganisationId = _organisationIdCreated,
                PrimaryContact                 = null,
                OrganisationTypeId             = _organisationTypeId,
                OrganisationData               = null,
                Status                         = OrganisationStatus.New
            };

            _username = "******";
            OrganisationHandler.InsertRecord(_organisation);
            _contactId    = Guid.NewGuid();
            _contactModel = new OrganisationContactModel
            {
                Id = _contactId,
                EndPointAssessorOrganisationId = _organisationIdCreated,
                OrganisationId = _id,
                Username       = _username,
                DisplayName    = "Joe Cool",
                Email          = "*****@*****.**",
                PhoneNumber    = "555 55555",
                Status         = OrganisationStatus.Live
            };

            _contactBeforeChange = new EpaContact
            {
                Id = _contactId,
                EndPointAssessorOrganisationId = _organisationIdCreated,
                Username    = _username,
                DisplayName = "Joe Cool",
                Email       = "*****@*****.**",
                PhoneNumber = "555 55555",
                Status      = OrganisationStatus.Live
            };

            _contactUpdated = new EpaContact
            {
                Id = _contactId,
                EndPointAssessorOrganisationId = _organisationIdCreated,
                Username    = _username,
                DisplayName = "Joe Cool changes",
                Email       = "*****@*****.**",
                PhoneNumber = "555 44444",
                Status      = OrganisationStatus.Live
            };
            OrganisationContactHandler.InsertRecord(_contactModel);
        }