public override async Task <IApplicationResult> CreateAsync(UserDto userDto) { return(await ExecuteAsync(async() => { var isAdmin = await _roleService.IsAdminAsync(_inventAppContext.UserEmail); if (!isAdmin) { throw new UnauthorizedAccessException($"Access Denied. Check permissions for User '{_inventAppContext.UserEmail}'"); } await _duplicateValidator.ValidateAsync(userDto); var user = _factory.Create(userDto); await _unitOfWork.GetRepository <User>().AddAsync(user); _auditService.AuditAsync(new Audit { Application = "InventApp", Environment = _appSettingsService.Environment.Name, User = _inventAppContext.UserEmail, EntityId = user.Id.ToString(), EntityName = user.GetType().Name, Entity = JsonConvert.SerializeObject(user), Action = AuditAction.Create }); var email = await _emailFactory.CreateForUserCreatedAsync(user); _emailService.SendAsync(email); return new OkApplicationResult <Guid> { Data = user.Id }; })); }