Beispiel #1
0
        //Handles the creation of a new user
        public async Task HandleCreate(Contracts.RegisterUser cmd)
        {
            //check if user already exists in event store
            if (await _store
                .Exists <Domain.User, UserId>(
                    new UserId(cmd.UserId)
                    ))
            {
                throw new InvalidOperationException(
                          $"Entity with id {cmd.UserId} already exists"
                          );
            }

            //create new instance of user from the command
            var user = new Domain.User(
                new UserId(cmd.UserId),
                Name.FromString(cmd.Name)
                );

            //save the new user to the event store
            await _store
            .Save <Domain.User, UserId>(
                user
                );
        }
        public async Task Handle(object command)
        {
            switch (command)
            {
            case Contracts.V1.Create cmd:
                if (await _store.Exists <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                        new ClassifiedAdId(cmd.Id)))
                {
                    throw new InvalidOperationException($"Entity with id {cmd.Id} already exists");
                }

                var classifiedAd = new Domain.ClassifiedAd.ClassifiedAd(
                    new ClassifiedAdId(cmd.Id),
                    new UserId(cmd.OwnerId));

                await _store.Save <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(classifiedAd);

                break;

            case Contracts.V1.SetTitle cmd:
                await this.HandleUpdate <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    _store, new ClassifiedAdId(cmd.Id),
                    c => c.SetTitle(ClassifiedAdTitle.FromString(cmd.Title)));

                break;

            case Contracts.V1.UpdateText cmd:
                await this.HandleUpdate <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    _store, new ClassifiedAdId(cmd.Id),
                    c => c.UpdateText(ClassifiedAdText.FromString(cmd.Text)));

                break;

            case Contracts.V1.UpdatePrice cmd:
                await this.HandleUpdate <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    _store, new ClassifiedAdId(cmd.Id),
                    c => c.UpdatePrice(Price.FromDecimal(cmd.Price, cmd.Currency, _currencyLookup)));

                break;

            case Contracts.V1.RequestToPublish cmd:
                await this.HandleUpdate <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    _store, new ClassifiedAdId(cmd.Id),
                    c => c.RequestToPublish());

                break;

            case Contracts.V1.Publish cmd:
                await this.HandleUpdate <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    _store, new ClassifiedAdId(cmd.Id),
                    c => c.Publish(new UserId(cmd.ApprovedBy)));

                break;

            default:
                throw new InvalidOperationException(
                          $"Command type {command.GetType().FullName} is unknown");
            }
        }
        private async Task HandleCreate(Contracts.V1.Create cmd)
        {
            if (await _store.Exists <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(
                    new ClassifiedAdId(cmd.Id)))
            {
                throw new InvalidOperationException($"Entity with id {cmd.Id} already exists");
            }

            var classifiedAd =
                new Domain.ClassifiedAd.ClassifiedAd(new ClassifiedAdId(cmd.Id), new UserId(cmd.OwnerId));
            await _store.Save <Domain.ClassifiedAd.ClassifiedAd, ClassifiedAdId>(classifiedAd);
        }
        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);
        }
Beispiel #5
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();
        }
        public async Task Handle(V1.BookRoom command)
        {
            var period = new StayPeriod(command.CheckIn, command.CheckOut);
            var roomId = new RoomId(command.RoomId);

            var exists = await _store.Exists <Booking>(command.BookingId);

            if (exists)
            {
                throw new ApplicationException($"Booking with id {command.BookingId} already exists");
            }

            var booking = new Booking();
            await booking.BookRoom(command.BookingId, command.GuestId, roomId, period, _availabilityCheck);

            await _store.Store(booking);
        }
        public async Task Handle(object command)
        {
            switch (command)
            {
            case Contracts.V1.RegisterUser cmd:
                if (await _store.Exists <Domain.UserProfile.UserProfile, UserId>(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 _store.Save <Domain.UserProfile.UserProfile, UserId>(userProfile);

                break;

            case Contracts.V1.UpdateUserFullName cmd:
                await this.HandleUpdate <Domain.UserProfile.UserProfile, UserId>(_store, new UserId(cmd.UserId),
                                                                                 profile => profile.UpdateFullName(FullName.FromString(cmd.FullName)));

                break;

            case Contracts.V1.UpdateUserDisplayName cmd:
                await this.HandleUpdate <Domain.UserProfile.UserProfile, UserId>(_store, new UserId(cmd.UserId),
                                                                                 profile => profile.UpdateDisplayName(
                                                                                     DisplayName.FromString(cmd.DisplayName, _checkText)));

                break;

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

                break;

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