public async Task <TResponse <bool> > CanInsertIdentityResourceProperty(InsertIdentityResourcePropertyReq identityResourceProperty)
        {
            try
            {
                var identityResource = await GetById(identityResourceProperty.IdentityResourceId);

                if (identityResource.IsSuccess)
                {
                    if (identityResource.Data != null)
                    {
                        var identityResourceProperties = await _readOnlyRepository.QueryAsync <IdentityResourceProperty>(
                            SqlQuery.IDENTITY_RESOURCE_PROPERTY_FIND_BY_KEY,
                            new
                        {
                            identityResourceProperty.Key,
                            identityResourceProperty.IdentityResourceId
                        });

                        if (identityResourceProperties != null)
                        {
                            if (identityResourceProperties.IsSuccess)
                            {
                                if (identityResourceProperties.Data.Any())
                                {
                                    return(await Fail <bool>(ErrorEnum.KeyHasExist.GetStringValue()));
                                }

                                return(await Ok(true));
                            }

                            return(await Fail <bool>(identityResourceProperties.Message));
                        }

                        return(await Ok(true));
                    }

                    return(await Fail <bool>(ErrorEnum.IdentityResourceNameHasNotExist.GetStringValue()));
                }

                return(await Fail <bool>(identityResource.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
        public async Task <TResponse <bool> > AddIdentityResourceProperty(int userId,
                                                                          InsertIdentityResourcePropertyReq identityResourceProperty)
        {
            try
            {
                var canInsert = await CanInsertIdentityResourceProperty(identityResourceProperty);

                if (canInsert.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.IDENTITY_RESOURCE_PROPERTY_INSERT, new
                    {
                        identityResourceProperty.Key,
                        identityResourceProperty.Value,
                        identityResourceProperty.IdentityResourceId,
                        UserCreated = userId,
                        DateCreated = DateTime.Now,
                        UserUpdated = userId,
                        DateUpdated = DateTime.Now
                    });

                    if (result != null)
                    {
                        if (result.IsSuccess)
                        {
                            if (result.Data == 0)
                            {
                                return(await Fail <bool>($"Insert IDENTITY_RESOURCE_PROPERTY {identityResourceProperty.Key} is failure"));
                            }

                            return(await Ok(true));
                        }

                        return(await Fail <bool>(result.Message));
                    }

                    return(await Fail <bool>($"Insert IDENTITY_RESOURCE_PROPERTY {identityResourceProperty.Key} is failure"));
                }

                return(await Fail <bool>(canInsert.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
 public async Task <ActionResult <int> > AddProperty(InsertIdentityResourcePropertyReq req)
 {
     return(Ok(await _identityResourceService.AddIdentityResourceProperty(UserId,
                                                                          req)));
 }