public void Read_NotThrowsException_StateIsValid() { var personKey = new PersonTableEntity { PersonId = Guid.Parse("00000000-1001-0000-0000-000000000000"), }; var personRepository = new PersonRepository(TestEnvironment.DBSettings); var person = personRepository.Read(personKey); Assert.IsNotNull(person); }
public void Update_NotThrowsException_StateIsValid() { var personKey = new PersonTableEntity { PersonId = Guid.Parse("00000000-1001-0000-0000-000000000000"), }; var personRepository = new PersonRepository(TestEnvironment.DBSettings); var person = personRepository.Read(personKey); person.UpdateTime = DateUtil.Now; Assert.IsTrue(personRepository.Update(person)); }
/// <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 void Create_NotThrowsException_StateIsValid() { var now = DateUtil.Now; var person = new PersonTableEntity { PersonId = Guid.NewGuid(), PersonCode = new string('X', 20), Name = new string('X', 256), LoginId = new string('X', 256), Title = new string('X', 100), Description = new string('X', 1024), SortNo = int.MaxValue, Status = PersonStatus.NORMAL.ToString(), CreateTime = DateTimeOffset.MaxValue, UpdateTime = DateTimeOffset.MaxValue, }; var personRepository = new PersonRepository(TestEnvironment.DBSettings); personRepository.Create(person); }
/// <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)); }
public async Task <ActionResult <IEnumerable <string> > > GetTrips() { string UserID = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; //string UserID = "666"; var tripList = new List <TripTableEntity>(); //Check if user exists var userList = new List <PersonTableEntity>(); var personQuery = new TableQuery <PersonTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, UserID)); TableContinuationToken tokenPerson = null; do { TableQuerySegment <PersonTableEntity> resultSegment = await _tablePerson.ExecuteQuerySegmentedAsync(personQuery, tokenPerson); tokenPerson = resultSegment.ContinuationToken; foreach (PersonTableEntity entity in resultSegment.Results) { userList.Add(entity); } } while (tokenPerson != null); //if user exits get trips else add user if (userList.Count() != 0) { var tripQuery = new TableQuery <TripTableEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, UserID)); TableContinuationToken tokenTrip = null; do { TableQuerySegment <TripTableEntity> resultSegment = await _tableTrip.ExecuteQuerySegmentedAsync(tripQuery, tokenTrip); tokenTrip = resultSegment.ContinuationToken; foreach (TripTableEntity entity in resultSegment.Results) { tripList.Add(entity); } } while (tokenTrip != null); if (tripList == null) { return(Ok("[]")); } } else { //Add user to Person table and return an empty triplist Person person = new Person { PersonId = UserID, Nickname = string.Empty, Avatar = string.Empty }; PersonTableEntity personTable = new PersonTableEntity(person); TableOperation insertOperation = TableOperation.Insert(personTable); await _tablePerson.ExecuteAsync(insertOperation); } return(Ok(tripList.OrderByDescending(a => a.StartDate))); }