public async Task <IActionResult> PostToAddNewGroup( [FromBody] AddCompanyRequest request, [FromServices] ICommandHandler <AddGroupCommand> _addGroupCommandHandler ) { _logger.LogInformation("Running POST method to ADD new group"); if (request == null) { request = new AddCompanyRequest(); } //Gets Bizfly identity from header. BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders(); AddGroupCommand command = new AddGroupCommand(bizflyIdentity, request.NewGroupId, bizflyIdentity.UserId, request.GroupName, "COMPANY"); await _addGroupCommandHandler.Handle(command); if (ModelState.IsValid) { _logger.LogInformation("New Group is created with id = {0}", request.NewGroupId); return(CreatedAtAction(nameof(Get), new { id = request.NewGroupId }, null)); } return(BadRequest(ModelState)); }
public async Task <Guid> AddGroup(AddGroupCommand command, CancellationToken cancellationToken) { if (command == null) { throw new ArgumentNullException(nameof(command)); } command.EnsureIsValid(); var groupPersisted = await authorizationRepository.GetGroupBy(command.Name, command.Domain, cancellationToken).ConfigureAwait(false); if (groupPersisted is not null) { throw new BusinessException(Messages.GroupAlreadyExist); } var group = new Group() { Name = command.Name, Description = command.Description, Domain = command.Domain }; await authorizationRepository.AddGroup(group, cancellationToken).ConfigureAwait(false); return(group.Id); }
void AndGivenRequest() { var words = new List <Wordki.Api.Featuers.Group.Add.Card>(); for (int i = 0; i < 2; i++) { words.Add(new Wordki.Api.Featuers.Group.Add.Card { Front = new Side { Value = "front-value", Example = "front-example" }, Back = new Side { Value = "back-value", Example = "back-example" } }); } var jsonObj = new AddGroupCommand { Name = "groupName", LanguageFront = 1, LanguageBack = 2, Cards = words }; var jsonString = JsonSerializer.Serialize(jsonObj); Request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); }
private void OnAddGroup() { if (Student.RelOrganizations == null) { Student.RelOrganizations = new ObservableCollection <RelOrganization>(); } RelOrganization relOrganization = new RelOrganization { RelOrganizationID = Guid.NewGuid() }; relOrganization.OrganizationID = SelectedGroupId; relOrganization.StudentID = Student.StudentGuid; AddedGroups.Add(relOrganization); Student.RelOrganizations.Add(relOrganization); Student.Organizations.Add(Organizations.SingleOrDefault(i => i.OrganizationID == relOrganization.OrganizationID)); Organizations.Remove(Organizations.SingleOrDefault(i => i.OrganizationID == relOrganization.OrganizationID)); if (Organizations.Count != 0) { SelectedGroupId = Organizations.FirstOrDefault().OrganizationID; } else { SelectedGroupId = new Guid(); } AddGroupCommand.RaiseCanExecuteChanged(); }
public void AddGroup_ThrowException_If_Command_IsNotValid(string name, string domain, string description) { var command = new AddGroupCommand(name, domain, description); Assert.ThrowsAsync <BusinessException>(async() => await authorizationAppService.AddGroup(command, CancellationToken.None)); }
private void ToolStripMenuAddGroup_Click(object sender, EventArgs e) { AddGroupCommand aGrp = new AddGroupCommand(data); inv.ExecuteAction(aGrp); CreateTree(); CheckUndoRedo(); }
public void AddGroup(string name) { Group group = new Group(name); ICommand command = new AddGroupCommand(university, group); commandsManager.Execute(command); uiManager.UpdateUI(); }
/// <summary> /// The Add Group Command /// /// The Add Group command allows the sending device to add group membership in a /// particular group for one or more endpoints on the receiving device. /// /// <param name="groupId" <see cref="ushort"> Group ID</ param > /// <param name="groupName" <see cref="string"> Group Name</ param > /// <returns> the command result Task </returns> /// </summary> public Task <CommandResult> AddGroupCommand(ushort groupId, string groupName) { AddGroupCommand command = new AddGroupCommand(); // Set the fields command.GroupId = groupId; command.GroupName = groupName; return(Send(command)); }
void AndGivenRequest() { var jsonObj = new AddGroupCommand { Name = "groupName", LanguageFront = 1, LanguageBack = 2, }; var jsonString = JsonSerializer.Serialize(jsonObj); Request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); }
private void ExecuteAddGroup() { IsAddingGroup = true; AddGroupCommand.RaiseCanExecuteChanged(); var newGroup = new GroupViewModel(new Group(), this, _commandFactory, _messageHandler); SelectedGroup = newGroup; IsAddingGroup = false; AddGroupCommand.RaiseCanExecuteChanged(); }
public async Task HandlerThrowsException_WhenCommandIsInvalid() { var identity = new BizflyIdentity(); //group id must be in Guid format string groupId = "878a04bd-ee90-40df-8745-354165893b7e"; string groupName = "test-group"; AddGroupCommand command = new AddGroupCommand(identity, groupId, identity.UserId, groupName, "COMPANY"); await _authoriserDecorator.Handle(command); }
public async Task AddGroup() { var command = new AddGroupCommand("Admin", "User", "Group admin"); authorizationRepositoryMock.GetGroupBy(command.Name, command.Domain, Arg.Any <CancellationToken>()) .Returns(default(Group)); var groupId = await authorizationAppService.AddGroup(command, CancellationToken.None); Assert.IsNotNull(groupId); Assert.IsFalse(groupId == Guid.Empty); await authorizationRepositoryMock.Received(1) .GetGroupBy(command.Name, command.Domain, Arg.Any <CancellationToken>()); await authorizationRepositoryMock.Received(1).AddGroup(Arg.Any <Group>(), Arg.Any <CancellationToken>()); }
public async Task AddGroup_Throw_Exception_If_Group_Already_Exist() { var group = new Group() { Name = "AllowGet", Domain = "user", Description = "Group of users" }; var command = new AddGroupCommand(group.Name, group.Domain, group.Description); authorizationRepositoryMock.GetGroupBy(command.Name, command.Domain, Arg.Any <CancellationToken>()) .Returns(group); Assert.ThrowsAsync <BusinessException>(async() => await authorizationAppService.AddGroup(command, CancellationToken.None), "Group already exist."); await authorizationRepositoryMock.Received(1).GetGroupBy(command.Name, command.Domain, Arg.Any <CancellationToken>()); }
private async void AddGroup(Group group) { if (!group.IsValid()) { return; } AddGroupCommand.NotifyCanExecute(false); await Task.Run(() => { var context = new KindergartenContext(); context.Groups.Add(group); context.SaveChanges(); }); AddGroupCommand.NotifyCanExecute(true); Pipe.SetParameter("added_group_result", group); Finish(); }
private async void OnDeleteGroup(Organization organization) { var result = await DialogHelper.ShowDialog(DialogType.Validation, "Are you sure you want to remove contact?"); if (result) { DeletedGroups.Add(Student.RelOrganizations.SingleOrDefault(i => i.OrganizationID == organization.OrganizationID)); Student.RelOrganizations.Remove(Student.RelOrganizations.SingleOrDefault(i => i.OrganizationID == organization.OrganizationID)); Student.Organizations.Remove(Student.Organizations.SingleOrDefault(i => i.OrganizationID == organization.OrganizationID)); Organizations.Add(_organizationsRepository.GetOrganization(organization.OrganizationID)); } if (Organizations.Count != 0) { SelectedGroupId = Organizations.FirstOrDefault().OrganizationID; } else { SelectedGroupId = new Guid(); } AddGroupCommand.RaiseCanExecuteChanged(); }
/// <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 ICommand BuildCommand() { ICommand result = new AddGroupCommand(); return(result); }
private void RaiseCanExecuteChanged(object sender, DataErrorsChangedEventArgs e) { SaveCommand.RaiseCanExecuteChanged(); AddContactCommand.RaiseCanExecuteChanged(); AddGroupCommand.RaiseCanExecuteChanged(); }
public bool AddGroup(IGroup group) { IGridCommand command = new AddGroupCommand(this, _setting, group, _allBlocks, OnGroupAdd); return command.Execute(); }
public bool AddGroup(IGroup group) { IGridCommand command = new AddGroupCommand(this, _setting, group, _allBlocks, OnGroupAdd); return(command.Execute()); }
public async Task <IActionResult> Add([FromBody] AddGroupCommand command) => await HandleCommand(command);
public async Task <ActionResult <int> > Add([FromBody] AddGroupCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task<Group> CreateGroupAsync(string name) { if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("A name must be specified."); if (Encoding.UTF8.GetByteCount(name) > 61) throw new ArgumentException("The name specified was too long."); await @lock.ReaderLockAsync(); try { if (closed) throw new ObjectDisposedException(GetType().Name); if (!IsLoggedIn) throw new NotLoggedInException(); if (Groups.Count >= 30) throw new InvalidOperationException("You have too many groups."); if (Groups.Where(g => name == g.Name).Count() > 0) throw new ArgumentException("A group with this name already exists."); Command cmd = new AddGroupCommand(name); AddGroupCommand response = await responseTracker.GetResponseAsync<AddGroupCommand>(cmd, defaultTimeout); Group group = new Group(this, response.Guid, name); Groups.AddGroup(group); OnGroupAdded(new GroupEventArgs(group, false)); return group; } finally { @lock.ReaderRelease(); } }
private void OnPropertyChanged(object sender, PropertyChangedEventArgs args) { SaveOrderCommand.RaiseCanExecuteChanged(); AddGroupCommand.RaiseCanExecuteChanged(); }
public async Task <IActionResult> Add(AddGroupCommand command, CancellationToken cancellationToken = default) { var groupId = await authorizationAppService.AddGroup(command, cancellationToken); return(Ok(groupId)); }