예제 #1
0
        public void DeleteForeighKeyOnMembershipIDFact()
        {
            var connection  = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction();

                // Memberships
                var membership = new MembershipEntity()
                {
                    Name = new Random().Next().ToString(CultureInfo.InvariantCulture), Password = @"password",
                };
                var memberships = new MembershipsRepository();
                membership.CreatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                var status = MembershipCreateStatus.ProviderError;
                if (!memberships.Create(membership, connection, transaction, out status))
                {
                    Assert.True(!true);
                }

                // Users
                var user = new UserEntity() /*ID = @"",*/ FamilyName
                {
                        = @"family name", GivenName = @"given name", AdditionalName = @"additional name", Description = @"description", CreatedOn = membership.CreatedOn, Enabled = true,
                };
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Role Create()
        {
            var connection  = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                this._entity.CreatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                if (!KandaRepository.Roles.Create(this._entity, connection, transaction))
                {
                    transaction.Rollback();
                }
                else
                {
                    this._entity.ID = KandaRepository.Roles.IdentCurrent(connection, transaction);
                    if (this._entity.ID < 1)
                    {
                        transaction.Rollback();
                    }
                    else if (!this.createMemberships(connection, transaction))
                    {
                        transaction.Rollback();
                    }
                    else if (!this.createAuthorizations(connection, transaction))
                    {
                        transaction.Rollback();
                    }
                    else
                    {
                        transaction.Commit();
                    }
                }

                return(this);
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public User Update()
        {
            var connection  = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                this._entity.UpdatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                if (!KandaRepository.Users.Update(this._entity, connection, transaction))
                {
                    transaction.Rollback();
                }
                else if (!this.createAttributes(connection, transaction))
                {
                    transaction.Rollback();
                }
                else if (!this.createHistory(connection, transaction))
                {
                    transaction.Rollback();
                }
                else
                {
                    transaction.Commit();
                }

                return(this);
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #4
0
        public void UpdateFact()
        {
            var connection  = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                var repository = new UsersRepository();

                var id        = long.MaxValue;
                var createdOn = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                Assert.True(repository.Create(new UserEntity()
                {
                    ID = id, FamilyName = @"Fact", GivenName = @"", AdditionalName = @"", Description = @"", Enabled = true, CreatedOn = createdOn
                }, connection, transaction));

                var updatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                Assert.True(repository.Update(new UserEntity()
                {
                    ID = id, FamilyName = @"Fact", GivenName = @"", AdditionalName = @"", Description = @"", Enabled = true, UpdatedOn = updatedOn
                }, connection, transaction));
                Assert.Equal(id, repository.Find(id, connection, transaction).ID);
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Membership Create()
        {
            var connection  = default(DbConnection);
            var transaction = default(DbTransaction);

            try
            {
                connection = this._factory.CreateConnection();
                connection.Open();

                transaction = connection.BeginTransaction(IsolationLevel.Serializable);

                this._entity.Enabled   = true;
                this._entity.CreatedOn = KandaRepository.GetUtcDateTime(connection, transaction);
                var status = MembershipCreateStatus.ProviderError;
                if (!KandaRepository.Memberships.Create(this._entity, connection, transaction, out status))
                {
                    switch (status)
                    {
                    case MembershipCreateStatus.DuplicateUserName:
                        // ユーザ名 '{0}' はすでに存在します。
                        break;

                    case MembershipCreateStatus.ProviderError:
                        // 作成に失敗しました。
                        break;
                    }
                    transaction.Rollback();
                }
                else
                {
                    if (this.ID < 1)
                    {
                        transaction.Rollback();
                    }
                    else if (!this.createUsers(connection, transaction))
                    {
                        transaction.Rollback();
                    }
                    else if (!this.createRoles(connection, transaction))
                    {
                        transaction.Rollback();
                    }
                    else if (!this.createAuthorization(connection, transaction))
                    {
                        transaction.Rollback();
                    }
                    else
                    {
                        transaction.Commit();
                    }
                }

                if (this.Created != null)
                {
                    this.Created(this, this._entity);
                }

                return(this);
            }
            catch
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw;
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }