Exemple #1
0
 /// <summary>
 /// Return an example for loading all users
 /// </summary>
 /// <returns></returns>
 public Response GetExamples()
 {
     return(Response.Create(new List <ReadUserModel> {
         ReadUserModel.CreateNewReadUser(Guid.NewGuid().ToString(), "Olivier", "Verplancke", "overplan", 1),
         ReadUserModel.CreateNewReadUser(Guid.NewGuid().ToString(), "Charme", "Balbuena", "charmeb", 2),
     }));
 }
Exemple #2
0
        public async Task Given_ReadUserModelIsStored_Should_ReturnedSame_When_Fetched()
        {
            // Arrange
            var readModel = ReadUserModel.CreateNewReadUser("aggregateRootId", "olivier", "verplancke", "overplan", 0);

            // Act
            await _sut.SaveOrUpdateUserAsync(readModel, default);

            var fetchedReadModels = (await _sut.LoadUsersAsync(default)).ToList();
Exemple #3
0
        public async Task <Unit> Handle(UpdateReadUserCommand request, CancellationToken cancellationToken)
        {
            var result = await _repository.SaveOrUpdateUserAsync(ReadUserModel.CreateNewReadUser(request.AggregateRootId, request.FirstName, request.LastName, request.UserName, request.Version), cancellationToken);

            if (string.IsNullOrEmpty(result))
            {
                //could not save / update read model
            }
            return(Unit.Value);
        }
Exemple #4
0
        public async Task <ReadUserModel> LoadUserByUserNameAsync(string userName, CancellationToken cancellationToken)
        {
            var entity = await _databaseContext.ReadUsers.SingleAsync(u => u.UserName == userName, cancellationToken);

            if (entity == null)
            {
                return(null);
            }

            return(ReadUserModel.CreateNewReadUser(entity.AggregateRootId, entity.FirstName, entity.LastName, entity.UserName, entity.Version));
        }
Exemple #5
0
        private async Task <ReadUserModel> LoadUserByAggregateRootIdAsync(string aggregateRootId, CancellationToken cancellationToken)
        {
            var entity = await _databaseContext.ReadUsers.FindAsync(new[] { aggregateRootId }, cancellationToken);

            if (entity == null)
            {
                return(null);
            }

            return(ReadUserModel.CreateNewReadUser(entity.AggregateRootId, entity.FirstName, entity.LastName, entity.UserName, entity.Version));
        }
Exemple #6
0
 public async Task <IEnumerable <ReadUserModel> > LoadUsersAsync(CancellationToken cancellationToken)
 {
     return((await _databaseContext.ReadUsers.ToListAsync(cancellationToken)).Select(r => ReadUserModel.CreateNewReadUser(r.AggregateRootId, r.FirstName, r.LastName, r.UserName, r.Version)));
 }