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; } }
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; } }
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()); }
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); }
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 }); }