Ejemplo n.º 1
0
        public async Task <TResponse <bool> > CanInsert(InsertApiEndpointReq apiEndpoint)
        {
            try
            {
                var apiEndpoints = await _readOnlyRepository.QueryAsync <ApiEndpoint>(SqlQuery.API_ENDPOINT_FIND_BY_NAME,
                                                                                      new
                {
                    apiEndpoint.Name,
                    apiEndpoint.Controller,
                    apiEndpoint.Action,
                    apiEndpoint.Method
                });

                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));
            }
        }
Ejemplo n.º 2
0
        public async Task <TResponse <bool> > Add(int userId,
                                                  InsertApiEndpointReq apiEndpoint)
        {
            try
            {
                var canInsert = await CanInsert(apiEndpoint);

                if (canInsert.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.API_ENDPOINT_INSERT, new
                    {
                        apiEndpoint.Name,
                        apiEndpoint.Controller,
                        apiEndpoint.Action,
                        apiEndpoint.Method,
                        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_ENDPOINT {apiEndpoint.Name} is failure"));
                            }

                            return(await Ok(true));
                        }

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

                    return(await Fail <bool>($"Insert API_ENDPOINT {apiEndpoint.Name} is failure"));
                }

                return(await Fail <bool>(canInsert.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Ejemplo n.º 3
0
 public async Task <ActionResult <int> > Add(InsertApiEndpointReq req)
 {
     return(Ok(await _apiEndpointService.Add(UserId,
                                             req)));
 }