Example #1
0
        public async Task <IActionResult> DeleteCategory(int id)
        {
            var command = new DeleteCategoryCommand(id);
            var result  = await _mediator.Send(command);

            return(Ok(result));
        }
Example #2
0
        public async Task Category_Delete()
        {
            var connection = TestHelper.GetConnection();
            var options    = TestHelper.GetMockDBOptions(connection);

            try
            {
                using (var context = new AppcentTodoContext(options))
                {
                    var service = new DeleteCategoryCommandHandler(context);
                    var command = new DeleteCategoryCommand();
                    command.Data = new DeleteCategoryRequest
                    {
                        CategoryId = 1,
                        UserName   = "******"
                    };
                    var result = await service.Execute(command);

                    Assert.True(result.Result.IsSuccess);
                }

                using (var context = new AppcentTodoContext(options))
                {
                    var task = context.AcCategories.FirstOrDefault(e => e.CategoryId == 1);
                    Assert.True(task.IsDeleted);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task <BaseApiResponse> Delete(DeleteRequest request)
        {
            request.CheckNotNull(nameof(request));
            //分类判断
            var category = _categoryQueryService.Find(request.Id);

            if (category == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该分类"
                });
            }
            //判断是否有子分类
            var children = _categoryQueryService.GetChildren(request.Id);

            if (children.Any())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "包含子分类,无法删除"
                });
            }
            //删除
            var command = new DeleteCategoryCommand(request.Id);
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Example #4
0
        public async Task <ActionResult> DeleteCategory(int id)
        {
            var command = new DeleteCategoryCommand(id);

            await _commandHandler.HandleAsync(command);

            return(Ok());
        }
        public async override Task<string> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
        {
            Entity = repo.Find(request);

            Result = repo.Delete(Entity);

            return Result;
        }
        public Task <HttpResponseMessage> Delete(int id)
        {
            var command = new DeleteCategoryCommand(id: id);

            var category = _service.Delete(command);

            return(CreateResponse(HttpStatusCode.OK, category));
        }
Example #7
0
        public async Task <IActionResult> Delete(DeleteCategoryCommand deleteCategoryCommand,
                                                 CancellationToken cancellationToken)
        {
            var sucesso = await _mediator.Send(deleteCategoryCommand, cancellationToken)
                          .ConfigureAwait(false);

            return(Ok(sucesso));
        }
        public async Task <CategoryDTO> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
        {
            var category = await _unitOfWork.GetRepository <Category>().FindAsync(request.Id);

            _unitOfWork.GetRepository <Category>().Delete(category);
            await _unitOfWork.SaveChangesAsync();

            return(_mapper.Map <CategoryDTO>(category));
        }
Example #9
0
        public async Task <IActionResult> DeleteCategory([FromRoute] int id)
        {
            var command = new DeleteCategoryCommand()
            {
                Id = id
            };

            return(Ok(await mediator.Send(command)));
        }
Example #10
0
        public async Task <APIResult> Delete([FromBody] DeleteCategoryCommand command)
        {
            var rs = await mediator.Send(command);

            return(new APIResult()
            {
                Result = rs
            });
        }
Example #11
0
        public async Task <IActionResult> Delete([FromBody] DeleteCategoryCommand deleteCategory)
        {
            var result = await _mediator.Send(deleteCategory);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
Example #12
0
        public ActionResult Delete(int id)
        {
            var command = new DeleteCategoryCommand {
                CategoryId = id
            };
            var result     = commandBus.Submit(command);
            var categories = categoryRepository.GetAll();

            return(PartialView("_CategoryList", categories));
        }
Example #13
0
 public ResultDto DeleteCategory(long id)
 {
     return(Result(() => {
         var command = new DeleteCategoryCommand
         {
             CategoryId = id,
         };
         CommandDispatcher.Send(command);
     }));
 }
Example #14
0
        public async Task <IHttpActionResult> Delete(Guid id)
        {
            var command = new DeleteCategoryCommand
            {
                Id = id
            };
            var response = await Bus.Send <DeleteCategoryCommand, DeleteCategoryCommandResponse>(command);

            return(Ok(response));
        }
Example #15
0
        public async Task <ActionResult <bool> > DeleteCategory(Guid id)
        {
            var deleteCategoryCommand = new DeleteCategoryCommand()
            {
                CategoryId = id
            };
            var deletedSuccess = await _mediator.Send(deleteCategoryCommand);

            return(Ok(deletedSuccess));
        }
Example #16
0
        public void ShouldRequireValidCategoryId()
        {
            var command = new DeleteCategoryCommand {
                Id = Guid.NewGuid()
            };

            Func <Task> act = async() => await SendAsync(command);

            act.Should().ThrowAsync <NotFoundException>();
        }
Example #17
0
        public ICommandResult Handle(DeleteCategoryCommand command)
        {
            bool result = _repository.Delete(command.Id);

            if (!result)
            {
                return(new CommandResult(false, "Falha ao deletar Categoria"));
            }

            return(new CommandResult(true, "Categoria deletada com sucesso!"));
        }
Example #18
0
        private void ConfirmDelete(int categoryID, string categoryTitle)
        {
            var command = new DeleteCategoryCommand(Repository, categoryID, categoryTitle)
            {
                ExecuteSuccessMessage = string.Format(CultureInfo.InvariantCulture, "Category \"{0}\" was deleted.",
                                                      categoryTitle)
            };

            Messages.ShowMessage(command.Execute());
            BindList();
        }
Example #19
0
        public async Task DeleteCategory(string accountName, string categoryName)
        {
            accountName = Uri.UnescapeDataString(accountName);
            var cmd = new DeleteCategoryCommand
            {
                AccountName  = accountName,
                CategoryName = categoryName
            };

            await this.mediator.Send(cmd);
        }
        // Check the UserId
        public async Task <IActionResult> DeleteCategory(int id)
        {
            var deleteCommand   = new DeleteCategoryCommand(id);
            var foundAndDeleted = await _mediator.Send(deleteCommand);

            if (!foundAndDeleted)
            {
                return(NotFound());
            }
            return(Ok());
        }
        public async Task Handle_GivenValidIdAndCategoryNotEmpty_ThrowsDeleteFailureException()
        {
            var validId = 1;

            var command = new DeleteCategoryCommand()
            {
                Id = validId
            };

            await ShouldThrowAsyncExtensions.ShouldThrowAsync <DeleteFailureException>(() => _handler.Handle(command, CancellationToken.None));
        }
        public async Task Handle_GivenInvalidId_ThrowsNotFoundException()
        {
            var invalidId = 10;

            var command = new DeleteCategoryCommand()
            {
                Id = invalidId
            };

            await ShouldThrowAsyncExtensions.ShouldThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None));
        }
Example #23
0
        public async Task HandleAsync(DeleteCategoryCommand message)
        {
            var category = await _uow.CategoryRepository.Get(message.Id);

            if (category == null)
            {
                throw new ArgumentNullException();
            }
            _uow.CategoryRepository.Delete(category);

            await _uow.Commit();
        }
Example #24
0
        public async Task <DeleteCategoryResponse> DeleteAsync(Guid id)
        {
            var command  = new DeleteCategoryCommand(id);
            var response = await _mediator.Send(command);

            if (response.IsSuccess)
            {
                _uow.Commit();
            }

            return(response.ProjectedAs <DeleteCategoryResponse>());
        }
Example #25
0
        public void ShouldNotCallHandleIfCategoryNotExist()
        {
            dbSetCategory.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Categories).Returns(dbSetCategory.Object);

            DeleteCategoryCommandHandler deleteCategoryCommandHandler = new DeleteCategoryCommandHandler(context.Object, stringLocalizer.Object);
            DeleteCategoryCommand        deleteCategoryCommand        = new DeleteCategoryCommand(id);

            Func <Task> act = async() => await deleteCategoryCommandHandler.Handle(deleteCategoryCommand, new CancellationToken());

            act.Should().ThrowAsync <NotFoundException>();
        }
        // DELETE /api/categories/5
        public void Delete(int id)
        {
            var command = new DeleteCategoryCommand {
                CategoryId = id
            };
            var result = commandBus.Submit(command);

            if (!result.Success)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Example #27
0
        public void DeleteCategoryCommandHandler_NotExisting_NoChange()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new DeleteCategoryCommandHandler(repository);
            var command    = new DeleteCategoryCommand(new Category());

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Category>());
        }
Example #28
0
        private void CorrectFlow()
        {
            Id = Builder <int> .CreateNew().Build();

            okResult    = Result.Ok(Id);
            errorResult = Result.Error <int>("Error");

            Command = Builder <DeleteCategoryCommand> .CreateNew()
                      .With(x => x.Id = Id).Build();

            mediator.Setup(m => m.Send(It.IsAny <DeleteCategoryCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(okResult);
        }