Ejemplo n.º 1
0
        public Task <Unit> Handle(UpdateSomeDataCommand request, CancellationToken cancellationToken)
        {
            try
            {
                using (var context = _dbContext)
                {
                    var aggregate = _someDataWriteRepository.Get(request.SomeDataId, context);
                    aggregate.ChangeFields(request);
                    _someDataWriteRepository.Save(aggregate, context);

                    context.SaveChanges();
                }

                _eventBus.Publish(new SomeDataUpdatedEvent(request.SomeDataId,
                                                           request.FirstName,
                                                           request.MiddleName,
                                                           request.LastName,
                                                           request.Title,
                                                           request.Color,
                                                           request.CreationDate,
                                                           request.FacebookUrl));

                return(Unit.Task);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 2
0
 public void ChangeFields(UpdateSomeDataCommand updateCommand)
 {
     if (updateCommand != null)
     {
         Color        = updateCommand.Color;
         CreationDate = updateCommand.CreationDate;
         FacebookUrl  = updateCommand.FacebookUrl;
         FirstName    = updateCommand.FirstName;
         LastName     = updateCommand.LastName;
         MiddleName   = updateCommand.MiddleName;
         Title        = updateCommand.Title;
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateSomeData([FromBody] SomeDataDto someDataDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updateSomeDataCommand = new UpdateSomeDataCommand(someDataDto.Id,
                                                                  someDataDto.FirstName,
                                                                  someDataDto.MiddleName,
                                                                  someDataDto.LastName,
                                                                  someDataDto.Title,
                                                                  new Color(someDataDto.Color),
                                                                  DateTime.Now,
                                                                  new FacebookUrl(someDataDto.FacebookUrl));

            await _commandBus.Send(updateSomeDataCommand);

            return(Ok());
        }
Ejemplo n.º 4
0
        public void ShouldAttributesOnChangeFields()
        {
            var aggregate     = BuildSomeAggregate();
            var updateCommand = new UpdateSomeDataCommand(aggregate.Id,
                                                          "NewFirstName",
                                                          "NewMiddleName",
                                                          "NewLastName",
                                                          "NewTitle",
                                                          new Color("#123"),
                                                          DateTime.Now,
                                                          new FacebookUrl("www.facebook.com/someuser"));

            aggregate.ChangeFields(updateCommand);

            Assert.Equal(updateCommand.LastName, aggregate.LastName);
            Assert.Equal(updateCommand.FirstName, aggregate.FirstName);
            Assert.Equal(updateCommand.MiddleName, aggregate.MiddleName);
            Assert.Equal(updateCommand.Color, aggregate.Color);
            Assert.Equal(updateCommand.CreationDate, aggregate.CreationDate);
            Assert.Equal(updateCommand.FacebookUrl, aggregate.FacebookUrl);
            Assert.Equal(updateCommand.Title, aggregate.Title);
        }
Ejemplo n.º 5
0
 public static Data.Contexts.Models.SomeData UpdateSomeDataCommandToPersistanceModel(UpdateSomeDataCommand updateSomeDataCommand)
 {
     return(new Data.Contexts.Models.SomeData
     {
         Id = updateSomeDataCommand.SomeDataId,
         FirstName = updateSomeDataCommand.FirstName,
         MiddleName = updateSomeDataCommand.MiddleName,
         LastName = updateSomeDataCommand.LastName,
         Title = updateSomeDataCommand.Title,
         Color = updateSomeDataCommand.Color.Value,
         CreationDate = updateSomeDataCommand.CreationDate,
         FacebookUrl = updateSomeDataCommand.FacebookUrl.Value
     });
 }