/// <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, }); }
public ActionResult <Person> UpdatePerson( [FromRoute] [Required(ErrorMessage = "DataAnnotationRequired")] [Guid(ErrorMessage = "DataAnnotationGuid")] string personId, [FromBody] PersonUpdateRequest request) { var personGuid = Guid.Parse(personId); var person = _personService.GetPerson(personGuid); if (person == null) { return(ErrorObjectResultFactory.NotFound()); } if (request.PersonCode != null && request.PersonCode != person.PersonCode && _personQueryService.ExistsPersonCode(request.PersonCode)) { return(ErrorObjectResultFactory.ValidationErrorDetail( string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayPersonPersonCode), "personCode")); } if (request.LoginId != null && request.LoginId != person.LoginId && _personQueryService.ExistsLoginId(request.LoginId)) { return(ErrorObjectResultFactory.ValidationErrorDetail( string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayPersonLoginId), "loginId")); } var dto = _mapper.Map <PersonUpdateRequest, PersonUpdateDto>(request); dto.PersonId = personGuid; var entity = _personService.UpdatePerson(dto); return(_mapper.Map <Domain.Entities.Person, Person>(entity)); }