Esempio n. 1
0
        public async Task <IActionResult> Delete(int id)
        {
            var command = new DeleteProjectCommand(id);
            await _mediator.Send(command);

            return(NoContent());
        }
Esempio n. 2
0
 public void DeleteProject(int projectId, int groupId)
 {
     using (ICommandSender commandSender = Factory.GetInstance <ICommandSender>().Open(CONST_DeleteProjectQueueName))
     {
         try
         {
             string ticketId = Guid.NewGuid().ToString();
             DeleteProjectCommand command = new DeleteProjectCommand
             {
                 ProjectId = projectId,
                 GroupId   = groupId,
                 TicketId  = ticketId
             };
             commandSender.SendCommand(command);
         }
         catch (Exception e)
         {
             e.ToString();
         }
         using (this.unitOfWorkProvider.CreateUnitOfWork())
         {
             var accountId = this.currentUserProvider.GetCurrentUser().GetAccount().Id;
             var project1  =
                 this.projectRepository.GetByAccountId(accountId).FirstOrDefault(x => x.Id == projectId);
             if (project1 != null)
             {
                 this.projectRepository.Delete(project1);
             }
         }
     }
 }
Esempio n. 3
0
        public async Task DeleteProjectTest()
        {
            _mediator.Setup(m => m.Send(It.IsAny <DeleteProjectCommand>(), new System.Threading.CancellationToken()))
            .Returns(Task.FromResult(new Core.ApiResponse.ApiResult
            {
                Code = Code.Ok
            }));

            _authorizationService.Setup(g => g.GetUser())
            .Returns(new Core.DataStructure.ControllerUser
            {
                UserName = "******",
                UserId   = 1234
            });

            var command = new DeleteProjectCommand
            {
                Id = 1,
            };

            var controller = new ProjectController(_mediator.Object, _log.Object, _authorizationService.Object, _projectQueries.Object);
            var result     = await controller.DeleteProjectAsync(command);

            Assert.NotNull(result);
            Assert.Equal(Code.Ok, result.Code);
        }
Esempio n. 4
0
        public ActionResult DeleteConfirmed(int projectId)
        {
            Request.ThrowIfDifferentReferrer();

            var project = _database.Projects
                          .FilterById(projectId)
                          .AsDbQuery()
                          .Include(p => p.Owner)
                          .SingleOrDefault();

            var currentUser = _userManager.FindById(User.Identity.GetUserId());

            if (project != null &&
                (project.Owner == currentUser || User.IsInRole(UserRoles.ADMIN)))
            {
                var command = new DeleteProjectCommand()
                {
                    Project = project,
                };

                _recordings.DeleteProjectData(project);

                try
                {
                    _dispatcher.Dispatch(command);
                }
                catch (Exception ex)
                {
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(HttpNotFound());
        }
        public override async Task DisposeAsync()
        {
            var deleteProjectCommand = new DeleteProjectCommand(createProjectDto.Id);

            await SendAsync(deleteProjectCommand);

            await base.DisposeAsync();
        }
        public void ShouldRequireValidProjectId()
        {
            var command = new DeleteProjectCommand {
                Id = 99
            };

            FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>();
        }
Esempio n. 7
0
        public void Delete(int id)
        {
            // you can use automapper to map source and destination

            var DeleteCommand = new DeleteProjectCommand(id);

            _bus.SendCommand(DeleteCommand);
        }
Esempio n. 8
0
        public async Task <ActionResult> Delete(Guid id)
        {
            var deleteProjectCommand = new DeleteProjectCommand()
            {
                ProjectId = id
            };
            await _mediator.Send(deleteProjectCommand);

            return(NoContent());
        }
Esempio n. 9
0
 public void Delete(DeleteProjectCommand command)
 {
     _db.Connection().Execute(
         "spDeleteProject",
         new
     {
         id = command.Id
     },
         commandType: CommandType.StoredProcedure
         );
 }
        public async Task <IActionResult> DeleteProject(DeleteProjectCommand command)
        {
            if (command is null)
            {
                return(BadRequest());
            }

            await _mediator.Send(command);

            return(NoContent());
        }
        public async Task <IActionResult> Delete([FromBody] DeleteProjectCommand command)
        {
            try
            {
                var output = await Mediator.Send(command);

                return(Ok(output));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public async Task ShouldDeleteProject()
        {
            var createProjectCommand = new CreateProjectCommand("project1", true);
            var createProjectDto     = await SendAsync(createProjectCommand);

            var deleteProjectCommand = new DeleteProjectCommand(createProjectDto.Id);

            await SendAsync(deleteProjectCommand);

            var projectEntity = await ExecuteDbContextAsync(db => db.Projects
                                                            .SingleOrDefaultAsync(p => p.Id.Equals(createProjectDto.Id))
                                                            );

            projectEntity.ShouldBeNull();
        }
Esempio n. 13
0
        public Task <bool> Handle(DeleteProjectCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(Task.FromResult(false));
            }
            _projectRepository.Remove(request.Id);
            if (Commit())
            {
                _bus.RaiseEvent(new ProjectDeletedEvent(request.Id, request.Name, request.Description, request.IsPrivate));
            }


            return(Task.FromResult(true));
        }
Esempio n. 14
0
        public override async Task DisposeAsync()
        {
            var deleteScenarioCommand = new DeleteScenarioCommand(createScenarioDto.Id, createProjectDto.Id);

            await SendAsync(deleteScenarioCommand);

            var deleteFeatureCommand = new DeleteFeatureCommand(createFeatureDto.Id, createProjectDto.Id);

            await SendAsync(deleteFeatureCommand);

            var deleteProjectCommand = new DeleteProjectCommand(createProjectDto.Id);

            await SendAsync(deleteProjectCommand);

            await base.DisposeAsync();
        }
Esempio n. 15
0
        public IActionResult Delete(Guid id)
        {
            var query   = new GetProjectQuery(id);
            var project = _bus.PublishQuery(query);

            // validation
            if (project == null)
            {
                return(NotFound());
            }

            var command = new DeleteProjectCommand(id);

            _bus.PublishCommand(command);
            return(Ok());
        }
        public void Execute_IntegrationTest_SQLite()
        {
            string          filePath  = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents = null;

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents = W3CEnumerable.FromStream(logStream).ToList();
            }

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                ICreateProjectCommand      createProjectCommand      = new CreateProjectCommand(dbContext, new ProjectValidator());
                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());
                IDeleteProjectCommand      deleteProjectCommand      = new DeleteProjectCommand(dbContext);


                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile);

                // create the request batch
                createRequestBatchCommand.Execute(logFile.Id, logEvents);

                //  run the delete command and check the end tables - should be 0 records
                deleteProjectCommand.Execute(project.Id);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM ProjectRequestAggregates");
                Assert.AreEqual(0, rowCount);

                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Requests");
                Assert.AreEqual(0, rowCount);

                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM LogFiles");
                Assert.AreEqual(0, rowCount);

                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Projects");
                Assert.AreEqual(0, rowCount);
            }
        }
Esempio n. 17
0
        public async Task ShouldGetProjectItem()
        {
            var createProjectCommand = new CreateProjectCommand("project1", true);
            var createProjectDto     = await SendAsync(createProjectCommand);

            var getProjectListQuery = new GetProjectQuery(createProjectDto.Id);
            var getProjectListDto   = await SendAsync(getProjectListQuery);

            getProjectListDto.ShouldNotBeNull();
            getProjectListDto.Id.ShouldBe(createProjectDto.Id);
            getProjectListDto.IsEnabled.ShouldBe(true);
            getProjectListDto.Name.ShouldBe("project1");

            var deleteProjectCommand = new DeleteProjectCommand(createProjectDto.Id);

            await SendAsync(deleteProjectCommand);
        }
        public async Task <IActionResult> DeleteProject(int id)
        {
            if (id <= 0)
            {
                return(new BadRequestObjectResult("invalid id"));
            }

            var command = new DeleteProjectCommand(id);
            var result  = await this._mediator.Send(command);

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult("Succes"));
        }
Esempio n. 19
0
        public async Task ShouldGetProjectList()
        {
            var createProjectCommand = new CreateProjectCommand("project1", true);
            var createProjectDto     = await SendAsync(createProjectCommand);

            var getProjectListQuery = new GetProjectListQuery();
            var getProjectListDto   = await SendAsync(getProjectListQuery);

            getProjectListDto.ShouldNotBeNull();
            getProjectListDto.Count.ShouldNotBe(0);
            getProjectListDto.Data.ShouldNotBeNull();
            getProjectListDto.Data.ShouldBeOfType <List <GetProjectDto> >();

            var deleteProjectCommand = new DeleteProjectCommand(createProjectDto.Id);

            await SendAsync(deleteProjectCommand);
        }
Esempio n. 20
0
        public async Task <ApiResult> DeleteProjectAsync([FromBody] DeleteProjectCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(InValidModelsError());
            }
            var user = _authorizationService.GetUser();

            if (user == null)
            {
                return(AuthorizeError());
            }

            _log.LogInformation("执行DeleteProjectAsync...控制器方法");

            return(await _mediator.Send(command));
        }
Esempio n. 21
0
        public ICommandResult Handle(DeleteProjectCommand command)
        {
            string id = command.Id.ToString();

            if (string.IsNullOrEmpty(id))
            {
                return(new CommandResult(MessagesUtil.InvalidIdentifier, false));
            }

            try
            {
                _repository.Delete(command);
                return(new CommandResult(MessagesUtil.DeletedSuccess, true));
            }
            catch
            {
                return(new CommandResult(MessagesUtil.DeleteError, false));
            }
        }
Esempio n. 22
0
        public async Task ProjectStatusInProgress_Executed_CancelProject()
        {
            //Arrange
            var project = new Project("Nome projeto 1", "descrição do projeto 1", 1, 2, 4000);
            var projectRepositoryMock = new Mock <IProjectRepository>();

            var id = 999999;

            var deleteProjectCommand        = new DeleteProjectCommand(id);
            var deleteProjectCommandHandler = new DeleteProjectCommandHandler(projectRepositoryMock.Object);

            projectRepositoryMock.Setup(p => p.GetByIdAsync(id).Result).Returns(project);

            //Act
            await deleteProjectCommandHandler.Handle(deleteProjectCommand, new CancellationToken());

            //Assert
            projectRepositoryMock.Verify(p => p.SaveChangesAsync(), Times.Once);
        }
        public async Task TestDeleteMethod()
        {
            // Arrange
            TestLambdaContext       context;
            APIGatewayProxyRequest  request;
            APIGatewayProxyResponse response;
            string json = System.Text.Json.JsonSerializer.Serialize(new
            {
                Title               = "Hello World",
                Type                = ProjectType.List.ToString(),
                Status              = Status.Active.ToString(),
                Priority            = Prioritization.High.ToString(),
                PercentageCompleted = 50
            });

            request = new APIGatewayProxyRequest
            {
                Headers        = new Dictionary <string, string>(),
                Body           = json,
                Path           = "/projects",
                PathParameters = new Dictionary <string, string>()
            };

            context = new TestLambdaContext();
            var createCommand = new CreateProjectCommand();
            var deleteCommand = new DeleteProjectCommand();

            // Act
            response = await createCommand.RunHandler(request, context);

            string projectId = response.Headers["Location"];

            request.Body = null;
            request.PathParameters["projectId"] = projectId.Split("/").Last();
            request.Path = projectId;
            response     = await deleteCommand.RunHandler(request, context);

            // Assert
            Assert.Equal(204, response.StatusCode);
            Assert.Null(response.Body);
            Assert.NotEmpty(response.Headers["Location"]);
        }
Esempio n. 24
0
        public async Task <ICommandResult> Handle(DeleteProjectCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Operação inválida", command.Notifications));
            }

            var projectDb = await _projectRepository.GetByIdAsync(command.Id);

            if (projectDb == null)
            {
                return(new GenericCommandResult(false, "Projeto não encontrado", command.Notifications));
            }


            await _projectRepository.DeleteAsync(command.Id);

            return(new GenericCommandResult(true, "Projeto removido com sucesso", projectDb));
        }
Esempio n. 25
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var deleteProjectCommand = new DeleteProjectCommand()
                {
                    ProjectId = id
                };
                await Mediator.Send(deleteProjectCommand);

                return(NoContent());
            }
            catch (UnauthorizedException e)
            {
                return(StatusCode(401, e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 26
0
        public async Task <IActionResult> DeleteAsync(DeleteProjectCommand deleteCommand)
        {
            if (deleteCommand.Id == Guid.Empty)
            {
                return(BadRequest("Id can't be empty."));
            }

            if (string.IsNullOrEmpty(deleteCommand.Name))
            {
                return(BadRequest("Name can't be empty."));
            }

            try
            {
                await _mediator.Send(deleteCommand);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 27
0
        public async Task <IActionResult> DeleteProject([FromBody] DeleteProjectCommand project)
        {
            var result = await Mediator.Send(project);

            return(result.Successful == true?Ok(result) : BadRequest(result.Exception.InnerException.Message ?? result.Exception.Message));
        }
Esempio n. 28
0
 public async Task <GenericCommandResult> Delete([FromBody] DeleteProjectCommand command, [FromServices] ProjectHandler handler)
 {
     return((GenericCommandResult)await handler.Handle(command));
 }
 public ICommandResult Delete(DeleteProjectCommand command)
 {
     return(_handler.Handle(command));
 }
Esempio n. 30
0
        public async Task <IActionResult> Delete(DeleteProjectCommand request, CancellationToken token)
        {
            var result = await Mediator.Send(request, token);

            return(Ok(result));
        }