public UserProfileCommandService(
            IAggregateStore store,
            CheckTextForProfanity checkText
            ) : base(store)
        {
            CreateWhen <V1.RegisterUser>(
                cmd => new UserId(cmd.UserId),
                (cmd, id) => UserProfile.Create(
                    new UserId(id), FullName.FromString(cmd.FullName),
                    DisplayName.FromString(cmd.DisplayName, checkText)
                    )
                );

            UpdateWhen <V1.UpdateUserFullName>(
                cmd => new UserId(cmd.UserId),
                (user, cmd)
                => user.UpdateFullName(FullName.FromString(cmd.FullName))
                );

            UpdateWhen <V1.UpdateUserDisplayName>(
                cmd => new UserId(cmd.UserId),
                (user, cmd) => user.UpdateDisplayName(
                    DisplayName.FromString(cmd.DisplayName, checkText)
                    )
                );

            UpdateWhen <V1.UpdateUserProfilePhoto>(
                cmd => new UserId(cmd.UserId),
                (user, cmd) => user.UpdateProfilePhoto(new Uri(cmd.PhotoUrl))
                );
        }
        public async Task Handle(object command)
        {
            switch (command)
            {
            case Contracts.V1.RegisterUser cmd:
                await HandleCreate(cmd);

                break;

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

                break;

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

                break;

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

                break;
            }
        }
예제 #3
0
        protected override void SetStateByEvent(IEvent @event)
        {
            switch (@event)
            {
            case UserRegistered e:
                Id          = e.UserId;
                FirstName   = FirstName.FromString(e.FirstName);
                LastName    = LastName.FromString(e.LastName);
                DisplayName = DisplayName.FromString(e.DisplayName);
                break;

            case UserNameUpdated e:
                FirstName = FirstName.FromString(e.FirstName);
                LastName  = LastName.FromString(e.LastName);
                break;

            case UserEmailUpdated e:
                Email = Email.FromString(e.Email);
                break;

            case UserDisplayNameUpdated e:
                DisplayName = DisplayName.FromString(e.DisplayName);
                break;

            default:
                throw new InvalidOperationException("امکان اجرای عملیات درخواستی وجود ندارد");
            }
        }
예제 #4
0
        public async Task Handle(object command)
        {
            switch (command)
            {
            case Contracts.V1.RegisterUser cmd:
                await HandleCreate(cmd);

                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");
            }
        }
예제 #5
0
 public void Configure(EntityTypeBuilder <UserProfile> builder)
 {
     builder.Property(c => c.FirstName).HasConversion(c => c.Value, d => FirstName.FromString(d));
     builder.Property(c => c.LastName).HasConversion(c => c.Value, d => LastName.FromString(d));
     builder.Property(c => c.DisplayName).HasConversion(c => c.Value, d => DisplayName.FromString(d));
     builder.Property(c => c.Email).HasConversion(c => c.Value, d => Email.FromString(d));
 }
예제 #6
0
        public void Handle(UpdateUserDisplayName command)
        {
            var user = _userProfileRepository.Load(command.UserId);

            if (user == null)
            {
                throw new InvalidOperationException($"کاربری با شناسه {command.UserId} یافت نشد.");
            }
            user.UpdateDisplayName(DisplayName.FromString(command.DisplayName));
            unitOfWork.Commit();
        }
        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);
        }
예제 #8
0
        public void Handle(RegisterUser command)
        {
            if (_userProfileRepository.Exists(command.UserId))
            {
                throw new InvalidOperationException($"قبلا کاربری با شناسه {command.UserId} ثبت شده است.");
            }

            UserProfile userProfile = new UserProfile(command.UserId,
                                                      FirstName.FromString(command.FirstName),
                                                      LastName.FromString(command.LastName),
                                                      DisplayName.FromString(command.DisplayName));

            _userProfileRepository.Add(userProfile);
            unitOfWork.Commit();
        }
예제 #9
0
        public async Task Handle(RegisterUserCommand command)
        {
            if (await _store.Exists <UserProfile, Guid>(new UserId(command.UserId)))
            {
                throw new InvalidOperationException($"Entity with id {command.UserId} already exists");
            }
            var user = new UserProfile(
                new UserId(command.UserId),
                FullName.FromString(command.FullName),
                DisplayName.FromString(command.DisplayName, _checkText));
            await _store.Save <UserProfile, Guid>(user);

            // await _repo.AddAsync(user);
            // await _repo.UnitOfWork.Commit();
        }
예제 #10
0
        private async Task HandleCreate(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();
        }
        public async Task Handle(UpdateUserDisplayNameCommand command)
        {
            // var user = await _repo.LoadAsync(new UserId(command.UserId));
            var user = await _store.Load <UserProfile, Guid>(command.UserId);

            if (user == null)
            {
                throw new InvalidOperationException(
                          $"Entity with id {command.UserId} cannot be found"
                          );
            }
            user.UpdateDisplayName(DisplayName.FromString(command.DisplayName, _checkText));
            await _store.Save <UserProfile, Guid>(user);

            // await _repo.UnitOfWork.Commit();
        }
예제 #12
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");
            }
        }