public async Task <TResponse <bool> > CanUpdate(UpdateIdentityResourceReq identityResource)
        {
            try
            {
                var identityResources = await _readOnlyRepository.QueryAsync <IdentityResource>(
                    SqlQuery.IDENTITY_RESOURCE_FIND_BY_NAME_AND_ID,
                    new
                {
                    identityResource.Name,
                    identityResource.Id
                });

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

                        return(await Ok(true));
                    }

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

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
        public async Task <TResponse <bool> > Update(int userId,
                                                     UpdateIdentityResourceReq identityResource)
        {
            try
            {
                var canUpdate = await CanUpdate(identityResource);

                if (canUpdate.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.IDENTITY_RESOURCE_UPDATE, new
                    {
                        identityResource.Id,
                        identityResource.Name,
                        identityResource.DisplayName,
                        identityResource.Description,
                        identityResource.Enabled,
                        identityResource.NonEditable,
                        identityResource.Required,
                        identityResource.Emphasize,
                        identityResource.ShowInDiscoveryDocument,
                        UserUpdated = userId,
                        DateUpdated = DateTime.Now
                    });

                    if (result != null)
                    {
                        if (result.IsSuccess)
                        {
                            if (result.Data == 0)
                            {
                                return(await Fail <bool>($"Update IDENTITY_RESOURCE {identityResource.Id} is failure"));
                            }

                            return(await Ok(true));
                        }

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

                    return(await Fail <bool>($"Update IDENTITY_RESOURCE {identityResource.Id} is failure"));
                }

                return(await Fail <bool>(canUpdate.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
 public async Task <ActionResult <int> > Update(UpdateIdentityResourceReq req)
 {
     return(Ok(await _identityResourceService.Update(UserId,
                                                     req)));
 }