public async Task <TResponse <bool> > Update(int userId, UpdateApiEndpointReq apiEndpoint) { try { var canUpdate = await CanUpdate(apiEndpoint); if (canUpdate.IsSuccess) { var result = await _writeRepository.ExecuteAsync(SqlQuery.API_ENDPOINT_UPDATE, new { apiEndpoint.Id, apiEndpoint.Name, apiEndpoint.Controller, apiEndpoint.Action, apiEndpoint.Method, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result != null) { if (result.IsSuccess) { if (result.Data == 0) { return(await Fail <bool>($"Update API_ENDPOINT {apiEndpoint.Id} is failure")); } return(await Ok(true)); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>($"Update API_ENDPOINT {apiEndpoint.Id} is failure")); } return(await Fail <bool>(canUpdate.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <TResponse <bool> > CanUpdate(UpdateApiEndpointReq apiEndpoint) { try { var apiEndpoints = await _readOnlyRepository.QueryAsync <ApiEndpoint>( SqlQuery.API_ENDPOINT_FIND_BY_NAME_AND_ID, new { apiEndpoint.Name, apiEndpoint.Controller, apiEndpoint.Action, apiEndpoint.Method, apiEndpoint.Id }); if (apiEndpoints != null) { if (apiEndpoints.IsSuccess) { if (apiEndpoints.Data.Any()) { return(await Fail <bool>(ErrorEnum.ApiEndpointNameHasExist.GetStringValue())); } return(await Ok(true)); } return(await Fail <bool>(apiEndpoints.Message)); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <int> > Update(UpdateApiEndpointReq req) { return(Ok(await _apiEndpointService.Update(UserId, req))); }