public async Task <ActionResult> DeleteGroup([FromRoute] int groupId, CancellationToken cancellationToken = default) { GroupExistsQuery existsQuery = new GroupExistsQuery { GroupId = groupId }; bool exists = await _mediator.Send(existsQuery, cancellationToken); if (!exists) { return(NotFound(new ErrorResource { StatusCode = StatusCodes.Status404NotFound, Message = $"Group with ID '{groupId}' does not exist" })); } DeleteGroupCommand deleteCommand = new DeleteGroupCommand { GroupId = groupId }; await _mediator.Send(deleteCommand, cancellationToken); return(NoContent()); }
public ICommandResult Handle(DeleteGroupCommand command) { ICommandResult result = new CommandResult(); _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Group, command.RequestHost }, "GroupCommandHandler.Handle(Delete)"); try { if (_groupRepository.CheckExists(command.Group)) { if (_groupRepository.Delete(command.Group)) { result = new CommandResult(200); } } else if (_groupRepository.Valid) { result = new CommandResult(400, new Notification("Group", "Could not be found")); } } catch (Exception e) { _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Group, command.RequestHost }, e); } return(result); }
public async void DeleteExistingGroupTest() { var group = new Group() { Id = 4, Name = "john", Memberships = new List <Membership>() }; var mem = new Membership() { Group = group, User = new User(), GroupId = 4, UserId = 2, }; group.Memberships.Add(mem); Memberships.Add(mem); Groups.Add(group); var command = new DeleteGroupCommand() { Id = 4 }; var handler = new DeleteGroupCommandHandler(Context); await handler.Handle(command, CancellationToken.None); Assert.Empty(Memberships); Assert.Empty(Groups); }
public void DeleteGroup(DeleteGroupCommand command) { var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); CascadeDeleteGroup(command.GroupId, command.OrganizationId, now); context.SaveChanges(); }
public async Task <IActionResult> Delete([FromRoute] string groupId) { var command = new DeleteGroupCommand(groupId); var result = await _mediator.Send(command); return(result != null?Ok(result) : NotFound()); }
public async Task <IActionResult> DeleteGroup(Guid id) { var command = new DeleteGroupCommand { Id = id }; return(await ExecuteRequest(command).ConfigureAwait(false)); }
public void ShouldRequireValidGroupId() { var command = new DeleteGroupCommand { GroupId = 99 }; FluentActions.Invoking(() => Testing.SendAsync(command)).Should().Throw <NotFoundException>(); }
public void RemoveGroup(CredentialGroup toBeRemoved) { ICommand command = new DeleteGroupCommand() { AllGroups = _currentData, DeletedGroup = toBeRemoved }; ExecuteCommand(command); }
public async Task <IActionResult> Delete([FromBody] DeleteGroupCommand deleteGroup) { var result = await Mediator.Send(deleteGroup); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public void TestInitialize() { var commandFactory = AssemblyConfiguration.Kernel.Get <CommandFactory>(); var queryFactory = AssemblyConfiguration.Kernel.Get <QueryFactory>(); _mapper = AssemblyConfiguration.Kernel.Get <IMapper>(); _createGroupCommand = commandFactory.GetInstance <CreateGroupCommand>(); _getGroupQuery = queryFactory.GetInstance <GetGroupsQuery>(); _sut = commandFactory.GetInstance <DeleteGroupCommand>(); }
public async Task ThrowDeleteFailureException_WhenLessonWithGroupExists() { var request = new DeleteGroupCommand { Id = 2 }; var handler = new DeleteGroupCommandHandler(Context); var exception = Assert.ThrowsAsync <DeleteFailureException>(async() => await handler.Handle(request, CancellationToken.None)); Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetDeleteFailureExceptionMessage(nameof(Group), request.Id, "There are lesson(s) with this group")); }
public async Task ThrowNotFoundException_WhenGroupIsNotExists() { var request = new DeleteGroupCommand { Id = 100 }; var handler = new DeleteGroupCommandHandler(Context); var exception = Assert.ThrowsAsync <NotFoundException>(async() => await handler.Handle(request, CancellationToken.None)); Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetNotFoundExceptionMessage(nameof(Group), request.Id)); }
public async Task DeleteGroup() { var request = new DeleteGroupCommand { Id = 1 }; var handler = new DeleteGroupCommandHandler(Context); var result = await handler.Handle(request, CancellationToken.None); Assert.IsFalse(Context.Groups.Any(x => x.Id == request.Id)); }
public void DeleteNonExistingGroupTest() { Groups.Add(new Group() { Id = 1, Name = "La pedrera", Memberships = new List <Membership>() }); Context.SaveChanges(); var command = new DeleteGroupCommand() { Id = 4 }; var handler = new DeleteGroupCommandHandler(Context); Assert.Throws <AggregateException>(() => handler.Handle(command, CancellationToken.None).Result); Assert.Single(Groups); }
public CommandResult Delete(Guid id) { DeleteGroupCommand command = new DeleteGroupCommand() { Group = id }; command.setRequestHost(HttpContext.Request.Host.ToString()); _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { Group = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method }); CommandResult result = (CommandResult)_groupHandler.Handle(command); _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { Group = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode }); HttpContext.Response.StatusCode = result.Code; return(result); }
public async Task <IActionResult> Delete( string id, [FromServices] ICommandHandler <DeleteGroupCommand> _deleteGroupCommandHandler) { _logger.LogInformation("Running DELETE method for GroupId = {0} ", id); //Gets Bizfly identity from header. BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders(); DeleteGroupCommand command = new DeleteGroupCommand(bizflyIdentity, id, bizflyIdentity.UserId); await _deleteGroupCommandHandler.Handle(command); if (ModelState.IsValid) { _logger.LogInformation("Group is deleted by ID = {0}", id); return(NoContent()); } return(BadRequest(ModelState)); }
public async Task DeleteGroupCommandHandler_ShouldSetDeleteFlagOnGroup() { // Arrange DeleteGroupCommand request = new DeleteGroupCommand { GroupId = 1 }; IEnumerable <Group> expectedGroups = new[] { new Group { GroupId = 1 } }; IQueryable <Group> queryableMock = expectedGroups .AsQueryable() .BuildMock() .Object; _unitOfWorkMock .Setup(m => m.Groups.GetById(request.GroupId)) .Returns(queryableMock); Group passedGroup = null; _unitOfWorkMock .Setup(m => m.Groups.Update(It.IsAny <Group>())) .Callback <Group>(g => passedGroup = g); DeleteGroupCommand.Handler handler = new DeleteGroupCommand.Handler(_unitOfWorkMock.Object); // Act await handler.Handle(request); // Assert Assert.NotNull(passedGroup); Assert.Equal(request.GroupId, passedGroup.GroupId); Assert.True(passedGroup.IsDeleted); _unitOfWorkMock.Verify(m => m.CommitAsync(It.IsAny <CancellationToken>()), Times.AtLeastOnce); }
private async void ExecuteDeleteGroupAsync() { IsDeletingGroup = true; DeleteGroupCommand.RaiseCanExecuteChanged(); var rv = await _bridge.DeleteGroupAsync(SelectedGroup.ID); if (rv.IsError()) { HueObjectCollectionBase <Error> errors = rv.To <Error>(); await _messageHandler.GetResponseAsync("Error", errors.FirstOrDefault().Description, MessageBoxButtons.OK); } else { ExecuteGetGroupsAsync(); } IsDeletingGroup = false; DeleteGroupCommand.RaiseCanExecuteChanged(); }
public Result <EmptyResult> DeleteGroup(DeleteGroupCommand command) { if (command.OrganizationId <= 0) { return(new Result <EmptyResult>(GroupServiceErrors.InvalidDeleteGroupDataError(nameof(command.OrganizationId)))); } if (command.GroupId <= 0) { return(new Result <EmptyResult>(GroupServiceErrors.InvalidDeleteGroupDataError(nameof(command.GroupId)))); } if (!groupRepository.GroupExists(command.GroupId, command.OrganizationId)) { return(new Result <EmptyResult>(GroupServiceErrors.GroupNotFoundError())); } groupRepository.DeleteGroup(command); return(new Result <EmptyResult>()); }
public async Task ShouldDeleteGroupAndChargeStations() { var group = await AddGroupAsync(); var station = await AddChargeStationAsync(group.Id); var command = new DeleteGroupCommand { GroupId = group.Id }; await Testing.SendAsync(command); group = await Testing.FindAsync <Group>(command.GroupId); group.Should().BeNull(); var chargeStation = await Testing.FindAsync <ChargeStation>(station.Id); chargeStation.Should().BeNull(); }
public ActionResult DeleteConfirmed(int groupId) { Request.ThrowIfDifferentReferrer(); var group = _database.Groups .FilterById(groupId) .SingleOrDefault(); if (group != null) { var command = new DeleteGroupCommand() { Group = group }; _dispatcher.Dispatch(command); return(RedirectToAction(nameof(Index))); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public IActionResult Delete(long id) { if (id <= 0) { return(BadRequest()); } var group = new Group(id); var deleteConnectorCommand = new DeleteGroupCommand() { Group = group }; var result = _mediator.Send(deleteConnectorCommand).Result; if (!string.IsNullOrEmpty(result.ErrorMessage)) { return(StatusCode(200, result)); } return(StatusCode(422, result)); }
/// <summary> /// ViewModel for main window. /// </summary> public MainWindowVM() { ContactService = new ContactService(); ContactVMs = ContactService.GetContactVMs(); GroupNames = new ObservableCollection <string>(ContactService.Groups.Select(it => it.Name)) { SystemGroupNames.ALL_CONTACTS }; SelectedGroup = SystemGroupNames.ALL_CONTACTS; AddGroupCommand = new AddGroupCommand(); AddContactToGroupCommand = new AddContactToGroupCommand(); RemoveContactFromGroupCommand = new RemoveContactFromGroupCommand(); EditContactCommand = new EditContactCommand(); AddContactCommand = new AddContactCommand(); DeleteContactCommand = new DeleteContactCommand(); DeleteGroupCommand = new DeleteGroupCommand(); }
public GroupMutation() { Name = "GroupMutation"; this.FieldAsyncWithScope <StringGraphType, string>( "create", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "name" } ), resolve: async(ctx, mediator) => { var command = new CreateGroupCommand() { Name = ctx.GetString("name") }; var id = await mediator.Send(command); return(id); } ); this.FieldAsyncWithScope <BooleanGraphType, bool>( "delete", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id" } ), resolve: async(ctx, mediator) => { var command = new DeleteGroupCommand() { Id = ctx.GetString("id") }; await mediator.Send(command); return(true); } ); this.FieldAsyncWithScope <BooleanGraphType, bool>( "update", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "name" } ), resolve: async(ctx, mediator) => { var command = new UpdateGroupCommand() { Id = ctx.GetString("id"), Name = ctx.GetString("name") }; await mediator.Send(command); return(true); } ); this.FieldAsyncWithScope <BooleanGraphType, bool>( "addUser", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "userId" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "groupId" } ), resolve: async(ctx, mediator) => { var command = new AddUserToGroupCommand() { UserId = ctx.GetString("userId"), GroupId = ctx.GetString("groupId") }; await mediator.Send(command); return(true); } ); this.FieldAsyncWithScope <BooleanGraphType, bool>( "removeUser", arguments: new QueryArguments ( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "userId" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "groupId" } ), resolve: async(ctx, mediator) => { var command = new RemoveUserFromGroupCommand() { UserId = ctx.GetString("userId"), GroupId = ctx.GetString("groupId") }; await mediator.Send(command); return(true); } ); }
public async Task <ActionResult <int> > Delete(DeleteGroupCommand command) { return(await Mediator.Send(command)); }
public async Task <IActionResult> Delete([FromBody] DeleteGroupCommand deleteGroup) { return(GetResponseOnlyResultMessage(await Mediator.Send(deleteGroup))); }
public async Task <ActionResult <ResponseWrapper> > DeleteGroupAsync([FromBody] DeleteGroupCommand command) { var result = await _mediator.Send(command); return(Ok(ResponseWrapper.CreateOkResponseWrapper(result))); }