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 TestSuspendHandler_ToThrowNotFound_WhenGroupNotFound() { var identity = new BizflyIdentity(); string groupId = "test-group-id"; string ownerId = "test-user-id"; _mockGroupRepository .Setup(repo => repo.GetByIdAsync(groupId)) .Throws(new ResourceNotFoundException()) .Verifiable(); // _mockGroupRepository //.Setup(repo => repo.AddOrUpdateAsync(It.IsAny<Group>(), null)) //.Throws(new ResourceNotFoundException()); SuspendGroupCommand command = new SuspendGroupCommand(identity, groupId, ownerId); await _suspendGroupHandler.Handle(command); _mockGroupRepository.Verify(); }
public AddGroupCommand(BizflyIdentity identity, string newGroupId, string ownerUserId, string groupName, string groupType) : base(identity) { NewGroupId = newGroupId; OwnerUserId = ownerUserId; GroupName = groupName; GroupType = groupType; }
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 <IActionResult> PostToSuspendGroup( string id, [FromServices] ICommandHandler <SuspendGroupCommand> _suspendGroupCommandHandler) { _logger.LogInformation("Running POST method to SUSPEND group by ID"); //Gets Bizfly identity from header. BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders(); SuspendGroupCommand command = new SuspendGroupCommand(bizflyIdentity, id, bizflyIdentity.UserId); await _suspendGroupCommandHandler.Handle(command); if (ModelState.IsValid) { return(Ok()); } return(BadRequest(ModelState)); }
public async Task <IActionResult> Get( string id, [FromServices] IQueryHandler <GetGroupSmallDetailDTOQuery, GroupSmallDetailDTO> _getGroupSmallDetailDTOQueryHandler ) { _logger.LogInformation("Running GET method to FETCH group by ID"); //Gets Bizfly identity from header. BizflyIdentity bizflyIdentity = Request.Headers.GetIdentityFromHeaders(); GetGroupSmallDetailDTOQuery query = new GetGroupSmallDetailDTOQuery(bizflyIdentity, id); GroupSmallDetailDTO result = await _getGroupSmallDetailDTOQueryHandler.HandleAsync(query); if (ModelState.IsValid) { return(Ok(result)); } return(BadRequest(ModelState)); }
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 static BizflyIdentity GetIdentityFromHeaders(this IHeaderDictionary headers) { var bizflyIdentity = new BizflyIdentity(); if (headers.TryGetValue("userId", out var userId)) { bizflyIdentity.UserId = userId.ToString(); } if (headers.TryGetValue("groupId", out var groupId)) { bizflyIdentity.GroupId = userId.ToString(); } if (headers.TryGetValue("groupType", out var groupType)) { bizflyIdentity.GroupType = userId.ToString(); } if (headers.TryGetValue("permissions", out var permissions)) { bizflyIdentity.Permissions = userId.ToString().Split(','); } return(bizflyIdentity); }
public GetGroupSmallDetailDTOQuery(BizflyIdentity identity, string id) : base(identity) { Id = id; }
public GetAllGroupSmallDetailDTOQuery(BizflyIdentity identity) : base(identity) { }
public void Test1() { var identity = new BizflyIdentity(); }
public ReactivateGroupCommand(BizflyIdentity identity, string companyId, string ownerId) : base(identity) { CompanyId = companyId; OwnerId = ownerId; }
public SuspendGroupCommand(BizflyIdentity identity, string companyId, string ownerId) : base(identity) { CompanyId = companyId; OwnerId = ownerId; }
public DeleteGroupCommand(BizflyIdentity identity, string id, string ownerId) : base(identity) { Id = id; OwnerUserId = ownerId; }
public Query(BizflyIdentity identity) { Identity = identity; }