public async Task <TResponse <bool> > CanUpdate(UpdateApiGroupReq apiGroup) { try { var apiGroups = await _readOnlyRepository.QueryAsync <ApiGroup>(SqlQuery.API_GROUP_FIND_BY_NAME_AND_ID, new { apiGroup.Name, apiGroup.Id }); if (apiGroups != null) { if (apiGroups.IsSuccess) { if (apiGroups.Data.Any()) { return(await Fail <bool>(ErrorEnum.ApiGroupNameHasExist.GetStringValue())); } return(await Ok(true)); } return(await Fail <bool>(apiGroups.Message)); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <TResponse <bool> > Update(int userId, UpdateApiGroupReq apiGroup) { try { var canUpdate = await CanUpdate(apiGroup); if (canUpdate.IsSuccess) { var result = await _writeRepository.ExecuteAsync(SqlQuery.API_GROUP_UPDATE, new { apiGroup.Id, apiGroup.Name, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result != null) { if (result.IsSuccess) { if (result.Data == 0) { return(await Fail <bool>($"Update API_GROUP {apiGroup.Id} is failure")); } return(await Ok(true)); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>($"Update API_GROUP {apiGroup.Id} is failure")); } return(await Fail <bool>(canUpdate.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <int> > Update(UpdateApiGroupReq req) { return(Ok(await _apiGroupService.Update(UserId, req))); }