コード例 #1
0
        private async Task HandleCreate(V1.RegisterUser cmd)
        {
            if (await _repository.Exists(new Domain.UserId(cmd.UserId)))
            {
                throw new InvalidOperationException($"Entity with id {cmd.UserId} already existes");
            }

            var userProfile = new Domain.UserProfile.UserProfile(new Domain.UserId(cmd.UserId), FullName.FromString(cmd.FullName), DisplayName.FromString(cmd.DisplayName, _checkText));

            await _repository.Add(userProfile);

            await _unitOfWork.Commit();
        }
コード例 #2
0
        private async Task HandleCreate(Contracts.V1.RegisterUser cmd)
        {
            if (await _store.Exists <Domain.UserProfile.UserProfile, UserId>(new UserId(cmd.Id)))
            {
                throw new InvalidOperationException($"User profile with Id ${cmd.Id} already exists");
            }

            var newUserProfile = new Domain.UserProfile.UserProfile(
                id: new UserId(cmd.Id),
                fullName: FullName.FromString(cmd.FullName),
                displayName: DisplayName.FromString(cmd.DisplayName, _checkText)
                );
            await _store.Save <Domain.UserProfile.UserProfile, UserId>(newUserProfile);
        }
コード例 #3
0
        public async Task Handle(object command)
        {
            switch (command)
            {
            case Contracts.V1.RegisterUser cmd:
                if (await _repository.Exists(new UserId(cmd.UserId)))
                {
                    throw new InvalidOperationException($"Entity with id {cmd.UserId} already exists");
                }

                var userProfile = new Domain.UserProfile.UserProfile(
                    new UserId(cmd.UserId),
                    FullName.FromString(cmd.FullName),
                    DisplayName.FromString(cmd.DisplayName, _checkText));

                await _repository.Add(userProfile);

                await _unitOfWork.Commit();

                break;

            case Contracts.V1.UpdateUserFullName cmd:
                await HandleUpdate(cmd.UserId,
                                   profile => profile.UpdateFullName(FullName.FromString(cmd.FullName)));

                break;

            case Contracts.V1.UpdateUserDisplayName cmd:
                await HandleUpdate(cmd.UserId,
                                   profile => profile.UpdateDisplayName(
                                       DisplayName.FromString(cmd.DisplayName, _checkText)));

                break;

            case Contracts.V1.UpdateUserProfilePhoto cmd:
                await HandleUpdate(cmd.UserId,
                                   profile => profile.UpdateProfilePhoto(new Uri(cmd.PhotoUrl)));

                break;

            default:
                throw new InvalidOperationException(
                          $"Command type {command.GetType().FullName} is unknown");
            }
        }