Пример #1
0
        public void Handle(UserUpdateCommand command)
        {
            var user = userRepository.Find(new UserId(command.Id));

            if (user == null)
            {
                throw new Exception("ユーザーは存在しません。");
            }


            if (command.Name != null)
            {
                user.ChangeName(new UserName(command.Name));
            }

            if (command.MailAddress != null)
            {
                user.ChangeMailAddress(new MailAddress(command.MailAddress));
            }

            userRepository.Save(user);
        }
Пример #2
0
        private static void TestApplicationService()
        {
            var defaultId          = "0";
            var defaultName        = "Kaleidot725";
            var defaultMailAddress = "*****@*****.**";
            var nextName           = "Kaleidot888";
            var nextMailAddress    = "*****@*****.**";

            var repository         = new ApplicationService.UserRepository();
            var applicationService = new ApplicationService.UserApplicationService(
                new ApplicationService.UserGetInfoService(repository),
                new ApplicationService.UserRegisterService(repository),
                new ApplicationService.UserDeleteService(repository),
                new ApplicationService.UserUpdateService(repository)
                );

            var registerCommand = new ApplicationService.UserRegisterCommand(defaultId, defaultName, defaultMailAddress);

            applicationService.Register(registerCommand);
            var newUserData = applicationService.Get(defaultId);

            Console.WriteLine(newUserData.Id + " " + newUserData.Name + " " + newUserData.MailAddress);

            var updateCommand = new ApplicationService.UserUpdateCommand(defaultId, nextName, nextMailAddress);

            applicationService.Update(updateCommand);
            var updateUserData = applicationService.Get(defaultId);

            Console.WriteLine(updateUserData.Id + " " + updateUserData.Name + " " + updateUserData.MailAddress);

            var deleteCommand = new ApplicationService.UserDeleteCommand(defaultId);

            applicationService.Delete(deleteCommand);
            var deleteUserData = applicationService.Get(defaultId);

            Console.WriteLine(deleteUserData == null ? "Null" : "Not Null");
        }
Пример #3
0
 public void Update(UserUpdateCommand command)
 {
     this.userUpdateService.Handle(command);
 }