public async Task <IActionResult> AddSystemFunctionGroup([FromBody] AddSystemGroupRequest request) { if (request.IsNull()) { return(ModelNullError()); } var identityClaims = (ClaimsIdentity)User.Identity; var model = new FnGroupAddCommandRequest { TransferObject = request }; var result = await Mediator.Send(model); return(HandleResponse(result, r => r)); }
public async Task <OperationResult <FnGroupAddCommandResponse> > Handle(FnGroupAddCommandRequest request, CancellationToken cancellationToken) { var response = new FnGroupAddCommandResponse(request.MessageId); OperationResult <FnGroupAddCommandResponse> result; //Validate Unique Name var group = await _dbContext.SystemFunctionGroup.SingleOrDefaultAsync(u => u.Name == request.TransferObject.Name); if (group.NotNull()) { result = new OperationResult <FnGroupAddCommandResponse>(EnumOperationResult.Duplicate, new List <ValidationError> { new ValidationError(nameof(request.TransferObject.Name), "Group Name already exists") }); } else { group = new SystemFunctionGroup { DisplayName = request.TransferObject.DisplayName, Name = request.TransferObject.Name, }; await _dbContext.SystemFunctionGroup.AddAsync(group, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); result = new OperationResult <FnGroupAddCommandResponse>(EnumOperationResult.Ok, null, response); result.AddDomainEvent(new SystemFunctionGroupAddEvent { GroupId = response.GroupId, }); } return(result); }