Ejemplo n.º 1
0
        public void UpdateOrganizationUser(UpdateOrganizationUserCommand command)
        {
            var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            //Update old entry at ObsoletedAt
            var organizationUserEntity = GetOrganizationUserEntity(command.OrganizationUserId, command.UserType, command.OrganizationId);

            organizationUserEntity.UpdatedAt = now;
            if (command.Email != null)
            {
                organizationUserEntity.Email = command.Email;
            }

            if (command.FirstName != null)
            {
                organizationUserEntity.FirstName = command.FirstName;
            }

            if (command.LastName != null)
            {
                organizationUserEntity.LastName = command.LastName;
            }

            if (command.IsActive != null)
            {
                organizationUserEntity.IsActive = command.IsActive.Value;
            }

            context.OrganizationUsers.Update(organizationUserEntity);
            this.context.SaveChanges();
        }
        public async Task <IHttpActionResult> UpdateOrganizationUser(string username,
                                                                     string role,
                                                                     EntityReference organization, string newRole)
        {
            try
            {
                if (!_userContext.CurrentUserIsSystemUser())
                {
                    return(Unauthorized());
                }

                if (string.IsNullOrWhiteSpace(username))
                {
                    throw new ArgumentException("Value cannot be null or whitespace.", nameof(username));
                }

                if (string.IsNullOrWhiteSpace(role))
                {
                    throw new ArgumentException("Value cannot be null or whitespace.", nameof(role));
                }

                if (organization == null)
                {
                    throw new ArgumentNullException(nameof(organization));
                }

                if (string.IsNullOrWhiteSpace(newRole))
                {
                    throw new ArgumentException("Value cannot be null or whitespace.", nameof(newRole));
                }

                if (!_userContext.CurrentUserIsSystemAdmin() && !_userContext.CurrentUserIsOrganizationAdmin(organization.Id))
                {
                    return(Unauthorized());
                }

                var cmd = new UpdateOrganizationUserCommand(username, role, organization, newRole);
                await _endpointInstance().SendWithSignalRMetaData(cmd, Request);

                return(this.Accepted());
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(InternalServerError());
            }
        }
Ejemplo n.º 3
0
        public void UpdateOrganizationUser_Name_Test()
        {
            var transactionMock = new Mock <IDbContextTransaction>();

            database.Setup(d => d.BeginTransaction()).Returns(transactionMock.Object);
            context.Setup(e => e.Database).Returns(database.Object);
            SetupOrganizationUsersDbSet(new List <OrganizationUserEntity>(new[] {
                new OrganizationUserEntity
                {
                    OrganizationUserEntityId = 5,
                    OrganizationId           = 1,
                    UserType      = 2,
                    FirstName     = "user0",
                    LastName      = "User0",
                    Email         = "*****@*****.**",
                    IsActive      = true,
                    TransactionId = "abc0"
                }
            }));

            var command = new UpdateOrganizationUserCommand
            {
                OrganizationId     = 1,
                OrganizationUserId = 5,
                UserType           = 2,
                FirstName          = "user1",
                LastName           = "User1",
                Email         = "*****@*****.**",
                IsActive      = true,
                TransactionId = "abc1"
            };



            organizationUserRepository.UpdateOrganizationUser(command);
            var result = organizationUserRepository.GetOrganizationUser(command.OrganizationUserId, command.UserType, command.OrganizationId);


            Assert.Equal(command.FirstName, result.FirstName);
            Assert.Equal(command.LastName, result.LastName);
            Assert.Equal(command.IsActive, result.IsActive);
        }
Ejemplo n.º 4
0
        public EmptyResult UpdateOrganizationUser(UpdateOrganizationUserCommand command)
        {
            this.logger.LogInformation("{} {}", command.OrganizationUserId, command.UserType);

            var organizationUser =
                organizationUserRepository.GetOrganizationUser(command.OrganizationUserId, command.UserType, command.OrganizationId);

            if (organizationUser == null)
            {
                return(new EmptyResult(OrganizationUserServiceErrors.NotFoundError()));
            }

            if (!string.IsNullOrWhiteSpace(command.Email) &&
                !string.Equals(command.Email, organizationUser.Email, StringComparison.CurrentCultureIgnoreCase) &&
                organizationUserRepository.IsEmailInUse(command.Email, organizationUser.OrganizationUserId))
            {
                return(new EmptyResult(OrganizationUserServiceErrors.EmailAlreadyInUseError()));
            }

            organizationUserRepository.UpdateOrganizationUser(command);
            return(new EmptyResult());
        }