public void Update(CircleUpdateCommand command) { using (var transaction = new TransactionScope()) { var id = new CircleId(command.Id); // この時点でUserのインスタンスが再構築されるが var circle = circleRepository.Find(id); if (circle == null) { throw new CircleNotFoundException(id); } if (command.Name != null) { var name = new CircleName(command.Name); circle.ChangeName(name); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "サークルは既に存在しています。"); } } circleRepository.Save(circle); transaction.Complete(); // Userのインスタンスは使われることなく捨てられる } }
public void Update(CircleUpdateCommand command) { using (var transaction = new TransactionScope()) { var id = new CircleId(command.Id); // 이 지점에서 User 객체가 복원되지만 var circle = circleRepository.Find(id); if (circle == null) { throw new CircleNotFoundException(id); } if (command.Name != null) { var name = new CircleName(command.Name); circle.ChangeName(name); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "이미 등록된 서클임"); } } circleRepository.Save(circle); transaction.Complete(); // User 객체를 사용하지 않고 처리가 끝남 } }
public void Put(string id, [FromBody] CirclePutRequestModel request) { var command = new CircleUpdateCommand(id, request.Name); circleApplicationService.Update(command); }