public async Task Perform(ReadOnlyMemory <byte> elevatorAction)
        {
            var action = JsonSerializer.Deserialize <ElevatorCommandBase>(elevatorAction.Span);

            var elevator = await _aggregateRepository.LoadAsync <Elevator>(action.ElevatorId);

            switch (action.ActionType)
            {
            case ElevatorCommandType.CloseDoor:
                await CloseDoors(action.ElevatorId);

                break;

            case ElevatorCommandType.OpenDoor:
                await OpenDoors(action.ElevatorId);

                break;

            case ElevatorCommandType.GoToFloor:
                var goToFloor = JsonSerializer.Deserialize <GoToFloorCommand>(elevatorAction.Span);
                await GoToFloor(goToFloor);

                break;
            }

            await _aggregateRepository.SaveAsync(elevator);
        }
        public AddToDoValidator(IAggregateRepository <ToDoList.ToDoList> toDoListAggregateRepository)
        {
            RuleFor(toDo => toDo.ToDoListId)
            .Custom((toDoListId, context) =>
            {
                var toDoListAggregate = toDoListAggregateRepository
                                        .LoadAsync(toDoListId)
                                        .GetAwaiter()
                                        .GetResult();

                var isValidToDoList = toDoListAggregate.GetCommittedEvents().Count > 0;

                if (!isValidToDoList)
                {
                    context.AddFailure($"The {nameof(ToDoList.ToDoList)} is not valid.");
                }
            });

            RuleFor(toDo => toDo.Label)
            .NotNull()
            .NotEmpty()
            .Length(3, 255);

            RuleFor(toDo => toDo.Description)
            .NotNull()
            .NotEmpty()
            .Length(3, 255);
        }
    public async Task <Unit> Handle(UpdateProfileCommand request, CancellationToken cancellationToken)
    {
        var user = await _aggregateRepository.LoadAsync <User>(_currentUser.Id);

        user.UpdateProfile(request.Name, request.Avatar, request.Bio);

        await _aggregateRepository.SaveAsync(user);

        return(Unit.Value);
    }
Esempio n. 4
0
        public async Task <Unit> Handle(JoinMeetupCommand request, CancellationToken cancellationToken)
        {
            var aggregate = await _aggregateRepository.LoadAsync <Meetup>(request.MeetupId.ToString(), cancellationToken);

            aggregate.Join(request.ParticipantId);

            await _aggregateRepository.SaveAsync(aggregate);

            return(Unit.Value);
        }
Esempio n. 5
0
    public async Task <Unit> Handle(EditNoteCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        note.Edit(_currentUser.Id, request.Title, request.Content, request.Comment);

        await _aggregateRepository.SaveAsync(note);

        return(Unit.Value);
    }
 public async Task <ReadResult <AR> > LoadAsync <AR>(IAggregateRootId id) where AR : IAggregateRoot
 {
     using (logger.BeginScope(s => s
                              .AddScope(Log.AggregateName, id.AggregateRootName)
                              .AddScope(Log.AggregateId, id.Value)))
     {
         logger.Debug(() => "Loading aggregate...");
         return(await realDeal.LoadAsync <AR>(id).ConfigureAwait(false));
     }
 }
    public async Task <Guid> Handle(AddNoteCommentCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        var comment = note.AddComment(_currentUser.Id, request.Text);

        await _aggregateRepository.SaveAsync(comment);

        return(comment.Id);
    }
Esempio n. 8
0
        public async Task <Unit> Handle(CancelMeetupCommand request, CancellationToken cancellationToken)
        {
            var aggregate = await _aggregateRepository.LoadAsync <Meetup>(request.MeetupId.ToString(), cancellationToken);

            aggregate.Cancel(request.OrganizerId);

            await _aggregateRepository.SaveAsync(aggregate);

            return(Unit.Value);
        }
    public async Task <Guid> Handle(AddMergeRequestCommentCommand request, CancellationToken cancellationToken)
    {
        var mergeRequest = await _aggregateRepository.LoadAsync <MergeRequest>(request.MergeRequestId);

        var comment = mergeRequest.AddComment(_currentUser.Id, request.Text);

        await _aggregateRepository.SaveAsync(comment);

        return(comment.Id);
    }
Esempio n. 10
0
    public async Task <Guid> Handle(CloneNoteCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        var cloneNote = note.Clone(_currentUser.Id, request.SpaceId);

        await _aggregateRepository.SaveAsync(cloneNote);

        return(cloneNote.Id);
    }
Esempio n. 11
0
        public async Task <Unit> Handle(CreateMeetupCommand request, CancellationToken cancellationToken)
        {
            var aggregate = await _aggregateRepository.LoadAsync <Meetup>(request.MeetupId.ToString(), cancellationToken);

            await aggregate.Register(request.MeetupId, request.OrganizerId, request.Subject, request.When, request.Description, request.Address, _meetupPolicy);

            await _aggregateRepository.SaveAsync(aggregate);

            return(Unit.Value);
        }
    public async Task <Unit> Handle(ChangePasswordCommand request, CancellationToken cancellationToken)
    {
        var user = await _aggregateRepository.LoadAsync <User>(_currentUser.Id);

        user.ChangePassword(_passwordService, request.OldPassword, request.NewPassword);

        await _aggregateRepository.SaveAsync(user);

        return(Unit.Value);
    }
Esempio n. 13
0
    public async Task <Unit> Handle(MergeNoteCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        note.Merge(request.SourceNoteId, request.Title, request.Content);

        await _aggregateRepository.SaveAsync(note);

        return(Unit.Value);
    }
        public async Task <Unit> Handle(AddCommentCommand request, CancellationToken cancellationToken)
        {
            var aggregate = await _aggregateRepository.LoadAsync <Meetup>(request.MeetupId.ToString(), cancellationToken);

            aggregate.AddComment(request.CommentatorId, request.Comment);

            await _aggregateRepository.SaveAsync(aggregate);

            return(Unit.Value);
        }
Esempio n. 15
0
    public async Task <Unit> Handle(UpdateUserRolesCommand request, CancellationToken cancellationToken)
    {
        var user = await _aggregateRepository.LoadAsync <User>(request.UserId);

        user.UpdateRoles(request.Roles);

        await _aggregateRepository.SaveAsync(user);

        return(Unit.Value);
    }
    public async Task <Unit> Handle(CloseMergeRequestCommand request, CancellationToken cancellationToken)
    {
        var mergeRequest = await _aggregateRepository.LoadAsync <MergeRequest>(request.MergeRequestId);

        mergeRequest.Close(_currentUser.Id);

        await _aggregateRepository.SaveAsync(mergeRequest);

        return(Unit.Value);
    }
Esempio n. 17
0
    public async Task <Guid> Handle(AddCommentReplyCommand request, CancellationToken cancellationToken)
    {
        var comment = await _aggregateRepository.LoadAsync <Comment>(request.CommentId);

        var replyComment = comment.Reply(_currentUser.Id, request.Text);

        await _aggregateRepository.SaveAsync(replyComment);

        return(replyComment.Id);
    }
Esempio n. 18
0
    public async Task <Unit> Handle(UpdateNoteTagsCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        note.UpdateTags(request.Tags);

        await _aggregateRepository.SaveAsync(note);

        return(Unit.Value);
    }
Esempio n. 19
0
    public async Task <Guid> Handle(CreateMergeRequestCommand request, CancellationToken cancellationToken)
    {
        var note = await _aggregateRepository.LoadAsync <Note>(request.NoteId);

        var mergeRequest = note.CreateMergeRequest(_noteChecker, _mergeRequestChecker, _currentUser.Id, request.Title,
                                                   request.Description);

        await _aggregateRepository.SaveAsync(mergeRequest);

        return(mergeRequest.Id);
    }
Esempio n. 20
0
        public async Task <Unit> Handle(StartToDo request, CancellationToken cancellationToken)
        {
            var toDo = await _aggregateRepository.LoadAsync(request.ToDoId);

            var @event = new ToDoStartedV1(toDo.Id, toDo.State.ToDoListId);

            toDo.When(@event);

            await _aggregateRepository.SaveAsync(toDo);

            return(Unit.Value);
        }
    public async Task <Unit> Handle(EditCommentCommand request, CancellationToken cancellationToken)
    {
        var comment = await _aggregateRepository.LoadAsync <Comment>(request.CommentId);

        await _resourceAuthorizationService.CheckAsync(comment, CommonOperations.Update);

        comment.Edit(request.Text);

        await _aggregateRepository.SaveAsync(comment);

        return(Unit.Value);
    }
Esempio n. 22
0
        public async Task <Unit> Handle(AddToDo request, CancellationToken cancellationToken)
        {
            var toDo = await _aggregateRepository.LoadAsync(null);

            var @event = new ToDoAddedV1(toDo.Id, request.ToDoListId, request.Label, request.Description);

            toDo.When(@event);

            await _aggregateRepository.SaveAsync(toDo);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(DeleteToDoList request, CancellationToken cancellationToken)
        {
            var toDoList = await _aggregateRepository.LoadAsync(request.ToDoListId);

            var @event = new ToDoListDeletedV1(toDoList.Id);

            toDoList.When(@event);

            await _aggregateRepository.SaveAsync(toDoList);

            return(Unit.Value);
        }
Esempio n. 24
0
    public async Task <Unit> Handle(DeleteSpaceCommand request, CancellationToken cancellationToken)
    {
        var space = await _aggregateRepository.LoadAsync <Space>(request.SpaceId);

        await _resourceAuthorizationService.CheckAsync(space, CommonOperations.Delete);

        space.Delete();

        await _aggregateRepository.SaveAsync(space);

        return(Unit.Value);
    }
Esempio n. 25
0
        public async Task <Unit> Handle(UpdateMeetupCommand request, CancellationToken cancellationToken)
        {
            var aggregate = await _aggregateRepository.LoadAsync <Meetup>(request.MeetupId.ToString(), cancellationToken);

            aggregate.ChangeSubject(request.OrganizerId, request.Subject);
            aggregate.ChangeWhen(request.OrganizerId, request.When);
            aggregate.ChangeDescription(request.OrganizerId, request.Description);
            aggregate.ChangeAddress(request.OrganizerId, request.Address);

            await _aggregateRepository.SaveAsync(aggregate);

            return(Unit.Value);
        }
Esempio n. 26
0
    public async Task <Guid> Handle(CreateNoteCommand request, CancellationToken cancellationToken)
    {
        var space = await _aggregateRepository.LoadAsync <Space>(request.SpaceId);

        var note = space.CreateNote(
            request.Title,
            request.Content,
            request.Status);

        await _aggregateRepository.SaveAsync(note);

        return(note.Id);
    }
Esempio n. 27
0
        public async Task <ElevatorDto> GetElevatorStatus(int elevatorId)
        {
            _elevatorsValidationHelper.ValidateElevatorId(elevatorId);

            var elevator = await _aggregateRepository.LoadAsync <Elevator>(elevatorId);

            if (elevator == null)
            {
                throw new NotFoundException($"Elevator with id: {elevatorId} not found.");
            }

            return(MapToElevatorDto(elevator));
        }
Esempio n. 28
0
        public async Task <AssignTaskResponseModel> Handle(AssignTaskRequest request, CancellationToken cancellationToken)
        {
            var taskAggregate = await _aggregateRepository.LoadAsync(request.Id.ToString());

            taskAggregate.Assign(request.Id, request.AssignTaskRequestModel);
            taskAggregate.Id = request.Id; //genel id bilgisi set edildi.
            await _aggregateRepository.SaveAsync(taskAggregate);

            return(new AssignTaskResponseModel
            {
                AssignedBy = request.AssignTaskRequestModel.AssignedTo,
                Id = request.Id,
                Status = (Core.Enums.TaskStatus)request.AssignTaskRequestModel.Status,
                Version = taskAggregate.Version
            });
        }
    public async Task <Unit> Handle(UpdateSpaceCommand request, CancellationToken cancellationToken)
    {
        var space = await _aggregateRepository.LoadAsync <Space>(request.SpaceId);

        await _resourceAuthorizationService.CheckAsync(space, CommonOperations.Update);

        space.Update(
            _spaceValidatorService,
            request.Name,
            request.BackgroundImage,
            request.Visibility);

        await _aggregateRepository.SaveAsync(space);

        return(Unit.Value);
    }
        public async Task <ChangeTaskStatusResponseModel> Handle(ChangeTaskStatusRequest request, CancellationToken cancellationToken)
        {
            var taskAggregate = await _aggregateRepository.LoadAsync(request.Id.ToString());

            taskAggregate.ChangeStatus(request.Id, request.ChangeTaskStatusRequestModel);
            taskAggregate.Id = request.Id; //genel id bilgisi set edildi.
            await _aggregateRepository.SaveAsync(taskAggregate);

            return(new ChangeTaskStatusResponseModel
            {
                UpdatedBy = request.ChangeTaskStatusRequestModel.UpdatedBy,
                Id = request.Id,
                Status = request.ChangeTaskStatusRequestModel.Status,
                Version = taskAggregate.Version
            });
        }