public async Task <TResponse <bool> > CanInsert(InsertApiGroupReq apiGroup) { try { var apiGroups = await _readOnlyRepository.QueryAsync <ApiGroup>(SqlQuery.API_GROUP_FIND_BY_NAME, new { apiGroup.Name }); 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> > Add(int userId, InsertApiGroupReq apiGroup) { try { var canInsert = await CanInsert(apiGroup); if (canInsert.IsSuccess) { var result = await _writeRepository.ExecuteAsync(SqlQuery.API_GROUP_INSERT, new { apiGroup.Name, 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 API_GROUP {apiGroup.Name} is failure")); } return(await Ok(true)); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>($"Insert API_GROUP {apiGroup.Name} is failure")); } return(await Fail <bool>(canInsert.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <int> > Add(InsertApiGroupReq req) { return(Ok(await _apiGroupService.Add(UserId, req))); }