Exemplo n.º 1
0
        /// <inheritdoc/>
        public Account RecreateAccountAndPerson(AccountCreateDto dto)
        {
            var now        = DateUtil.Now;
            var personId   = Guid.NewGuid();
            var personCode = personId.ToString("N").Substring(0, 20);

            while (_personQueryService.ExistsPersonCode(personCode))
            {
                personCode = Guid.NewGuid().ToString("N").Substring(0, 20);
            }

            var account = _accountRepository.Read(new AccountTableEntity {
                AccountId = dto.AccountId
            });

            account.PersonId      = personId;
            account.LastLoginTime = now;

            var person = new PersonTableEntity
            {
                PersonId    = personId,
                PersonCode  = personCode,
                LoginId     = dto.LoginId,
                Name        = dto.Name,
                Title       = string.Empty,
                Description = string.Empty,
                Status      = PersonStatus.NORMAL.ToString(),
                SortNo      = int.MaxValue,
                CreateTime  = now,
                UpdateTime  = now,
            };

            using (var tran = new TransactionScope())
            {
                _accountRepository.Update(account);
                _personRepository.Create(person);
                tran.Complete();
            }

            return(new Account
            {
                AccountId = account.AccountId,
                Person = _personQueryService.GetPerson(personId),
                Roles = JsonUtil.Deserialize <List <string> >(account.Roles),
                CreateTime = account.CreateTime,
                LastLoginTime = account.LastLoginTime,
            });
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public Person CreatePerson(PersonCreateDto dto)
        {
            var now    = DateUtil.Now;
            var entity = new PersonTableEntity
            {
                PersonId    = Guid.NewGuid(),
                PersonCode  = dto.PersonCode,
                LoginId     = dto.LoginId,
                Name        = dto.Name,
                Title       = dto.Title,
                Description = dto.Description,
                Status      = dto.Status,
                SortNo      = dto.SortNo,
                CreateTime  = now,
                UpdateTime  = now,
            };

            using (var tran = new TransactionScope())
            {
                _personRepository.Create(entity);

                foreach (var tag in dto.Tags)
                {
                    _tagRepository.Create(new TagTableEntity
                    {
                        TagId       = Guid.NewGuid(),
                        TargetId    = entity.PersonId,
                        Value       = tag,
                        TargetTable = "Person",
                        CreateTime  = now,
                    });
                }

                tran.Complete();
            }
            return(_personQueryService.GetPerson(entity.PersonId));
        }