コード例 #1
0
        public async Task <bool> Handle(UpdateProjectInfoCommand request, CancellationToken cancellationToken)
        {
            var projectDomain = _ProjectRepository.GetById(request.Id).Result.ToDomain <Project>(_Mapper);

            projectDomain.Validate();

            projectDomain.SetDescription(request.Description, request.LongDescription);

            #region Persistence

            await _ProjectRepository.Update(projectDomain.ToModel <Command.Project>(_Mapper));

            await _UnitOfWork.Commit();

            #endregion

            #region Bus

            var publishMessage = new Message();
            publishMessage.MessageType = "UpdateProject";
            publishMessage.SetData(projectDomain.ToQueryModel <Query.Project>(_Mapper));

            await _Bus.SendMessage(publishMessage);

            #endregion

            return(true);
        }
コード例 #2
0
        public void ProjectCommandHandler_Handle_UpdateProjectInfoCommand_EditProject_ValidInput(bool isFacebookProject, string description, string longDescription)
        {
            IRequestHandler <UpdateProjectInfoCommand, bool> handler = GetCommandHandlerInstance();
            var commandData = new UpdateProjectInfoCommand()
            {
                Id = isFacebookProject ? FacebookId : WindowsProjectId, Description = description, LongDescription = longDescription
            };

            var result = handler.Handle(commandData, default).Result;

            result.Should().BeTrue();
        }
コード例 #3
0
        public void ProjectCommandHandler_Handle_UpdateProjectInfoCommand_EditProject_InvalidInput(bool isFacebookProject, string description, string longDescription)
        {
            IRequestHandler <UpdateProjectInfoCommand, bool> handler = GetCommandHandlerInstance();
            var commandData = new UpdateProjectInfoCommand()
            {
                Id = isFacebookProject ? FacebookId : WindowsProjectId, Description = description, LongDescription = longDescription
            };

            Action handle = () => handler.Handle(commandData, default).Wait();

            handle.Should().Throw <ValidationException>();
        }
コード例 #4
0
        //public async Task<AddUserProjectPayload> AddUserProject(
        //    UserProjectInput input,
        //    [Service] IServiceProvider serviceProvider,
        //    CancellationToken cancellationToken)
        //{
        //    var addUserProjectCommand = new AddUserProjectCommand()
        //    {
        //        ProjectId = input.ProjectId,
        //        UserId = input.UserId
        //    };
        //    using (var scope = serviceProvider.CreateScope())
        //    {
        //        var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
        //        try
        //        {
        //            var response = await mediator.Send(addUserProjectCommand, cancellationToken);
        //            return new AddUserProjectPayload(response.Project, response.User);
        //        }
        //        catch (ValidationException e)
        //        {
        //            var userErrors = new List<UserError>();
        //            e.Message.Split(";").ForAll(item =>
        //            {
        //                userErrors.Add(new UserError(item, item));
        //            });
        //            return new AddUserProjectPayload(userErrors);
        //        }
        //    }
        //}

        //public async Task<AddUserProjectPayload> RemoveUserProject(
        //    UserProjectInput input,
        //    [Service] IServiceProvider serviceProvider,
        //    CancellationToken cancellationToken)
        //{
        //    var removeUserProjectCommand = new RemoveUserProjectCommand()
        //    {
        //        ProjectId = input.ProjectId,
        //        UserId = input.UserId
        //    };
        //    using (var scope = serviceProvider.CreateScope())
        //    {
        //        var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
        //        try
        //        {
        //            var response = await mediator.Send(removeUserProjectCommand, cancellationToken);
        //            return new AddUserProjectPayload(response.Project, response.User);
        //        }
        //        catch (ValidationException e)
        //        {
        //            var userErrors = new List<UserError>();
        //            e.Message.Split(";").ForAll(item =>
        //            {
        //                userErrors.Add(new UserError(item, item));
        //            });
        //            return new AddUserProjectPayload(userErrors);
        //        }
        //    }
        //}

        public async Task <AddProjectPayload> UpdateProjectInfo(
            UpdateProjectInfoInput input,
            [Service] IServiceProvider serviceProvider,
            CancellationToken cancellationToken)
        {
            var updateProjectInfoCommand = new UpdateProjectInfoCommand()
            {
                Id              = input.Id,
                Description     = input.Description,
                LongDescription = input.LongDescription
            };

            using (var scope = serviceProvider.CreateScope())
            {
                var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();
                try
                {
                    var response = await mediator.Send(updateProjectInfoCommand, cancellationToken);

                    return(new AddProjectPayload(response));
                }
                catch (ValidationException e)
                {
                    var userErrors = new List <UserError>();
                    e.Message.Split(";").ForAll(item => { userErrors.Add(new UserError(item, item)); });
                    return(new AddProjectPayload(userErrors));
                }
                catch (ElementNotFoundException e)
                {
                    return(new AddProjectPayload(new List <UserError>
                    {
                        new UserError("Элемент не найден", "PROJ-not_found")
                    }));
                }
                catch (QueryArgumentException e)
                {
                    return(new AddProjectPayload(new List <UserError>
                    {
                        new UserError(e.Message, e.Message)
                    }));
                }
            }
        }
コード例 #5
0
        public async Task <Infrastructure.Database.Query.Model.Project.Project> Handle(UpdateProjectInfoCommand request, CancellationToken cancellationToken)
        {
            var projectDomain = _ProjectRepository.GetById(request.Id).Result.ToDomain <Project>(_Mapper);

            projectDomain.Validate();

            projectDomain.SetDescription(request.Description, request.LongDescription);

            #region Persistence

            await _ProjectRepository.Update(projectDomain.ToModel <Command.Project>(_Mapper));

            await _UnitOfWork.Commit();

            #endregion

            #region Bus

            var publishMessage = new Message();
            publishMessage.MessageType = "UpdateProject";
            var response = projectDomain.ToQueryModel <Query.Project>(_Mapper);
            publishMessage.SetData(response);

            await _SendEndpointProvider.Send(publishMessage, cancellationToken);

            #endregion

            return(response);
        }