How to execute CRUD actions through API?

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
lfernandes
User
Posts: 77

How to execute CRUD actions through API?

Post by lfernandes »

How can I for example execute a record deletion action using an ASP.NET Maker API action? Do I need to enable any advanced settings?

Tried to test via url:
http://localhost:9011/api/delete/tacontatos/5824

And via code:

$("#btn-id").click(function() {
     var url = "/api/",
          object = "tacontatos", // "cars" is the table variable name
          action = "delete", // Get response from Add page
          key = 5824,
       $.get(url + action + "/" + object + "/" + key , function(res) {
         if (res && res.success) {
             var row = res[object];
             alert(JSON.stringify(row)); // Show output JSON
         } else {
             alert(res.failureMessage);
         }
     });
});

Returning the following error:
"An unhandled exception occurred while processing the request.
InvalidOperationException: Sequence contains in matching element
System.Linq.ThrowHelper.ThrowNoMatchException()"


MichaelG
User
Posts: 1111

Post by MichaelG »

You can test via the generated Swagger UI. Read Tools -> Advanced Settings -> Use Swagger UI for API:
https://aspnetmaker.dev/doc/hh_start.htm#tools.htm


lfernandes
User
Posts: 77

Post by lfernandes »

Follow the result of the swagger test:

Curl
curl -X GET "http://localhost:9011/api/delete/tacontatos/167" -H "accept: /"

Request URL
http://localhost:9011/api/delete/tacontatos/167

Server response
Code Details
500 Error: Internal Server Error

Undocumented

Response body

System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at AspNetMaker2021.Models.ead.GetTableName(String tblVar) in C:\sistemas\iqsis.com.br\wwwroot\.net\estacio\ead\Models\aspnetfn.cs:line 5686
   at AspNetMaker2021.Models.ead.AdvancedSecurityBase.LoadTablePermissions(String tblVar) in C:\sistemas\iqsis.com.br\wwwroot\.net\estacio\ead\Models\src\AdvancedSecurityBase.cs:line 793
   at AspNetMaker2021.Models.ead.PermissionHandler.HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) in C:\sistemas\iqsis.com.br\wwwroot\.net\estacio\ead\Models\src\PermissionHandler.cs:line 117
   at Microsoft.AspNetCore.Authorization.AuthorizationHandler`1.HandleAsync(AuthorizationHandlerContext context)
   at Microsoft.AspNetCore.Authorization.DefaultAuthorizationService.AuthorizeAsync(ClaimsPrincipal user, Object resource, IEnumerable`1 requirements)
   at Microsoft.AspNetCore.Authorization.Policy.PolicyEvaluator.AuthorizeAsync(AuthorizationPolicy policy, AuthenticateResult authenticationResult, HttpContext context, Object resource)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS
=======
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Cookie: .AspNetCore.Antiforgery.eUSSJgoZt9U=CfDJ8DIIZr1mIJVBs5tETpWDnuEVbaIq4YA5PAK5ZbnG7f0WHRwUD0FuRLgJK7MV1XrA2ml3uTc8LnbQuKYuwJoVMapkvGXrbo8vcK-1azl9HszEdKBOepduelxFF_54GJLiK8UhhqbfrW2jXZZGjyVHG7E; .ead.Session=CfDJ8DIIZr1mIJVBs5tETpWDnuFSCtHf6gaRc%2FM6xwoCM7KhdYI7WV3rm3jV1AvKwHZJjcEF%2BtL6ua6yiU7YfyUiO5m8KJs1MwflsPdHGszgzZlBGQm4UBkuZDpd40P2h0ZpVkzCyJABsDEaTr%2BKNdXG3ZokwHBt3x33NHoBz2pbz4gp; .AspNetCore.Cookies=CfDJ8DIIZr1mIJVBs5tETpWDnuEQZz0_MjmX485929PPY4ZWL4SChelVsqejdX-HDUD4OdO3ruGSpSKDAa9RgfKGbgdw7Nb5RNW8d8TTWcbKSoY2P4G_LY3Svi9b2esTFyFsWGIVclpzNNvcohgtm5pgamsPjzeyTmQ6dKuEF0prC0lNlXyxSoBi4BSrXufQzqXg95W1Yg4ZiRpO5T-95zT-fdl_33iTlR8YLIlsCXSuKqRhUYmQPxJ6fwShpD6CzvlxAmwCJ-pfudL9DD-i3wRofuL_s8pz5yOGFVxYFLkGjpETwvX62Quuno3N9NrMum40X-YjgFlLiv4cuY5HWuviGz4zgVfG3He5KgGW4gXSkoN_HgFpsPb3WsQEqPQ_D_zyIuLM2V0VBnavEmf8Uo8CbJY
Host: localhost:9011
Referer: http://localhost:9011/Swagger/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
sec-ch-ua: "Avast Secure Browser";v="95", "Chromium";v="95", ";Not A Brand";v="99"
Sec-GPC: 1
DNT: 1
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty

Response headers
 access-control-allow-credentials: true 
 access-control-allow-headers: Content-type 
 access-control-allow-methods: GET,POST,PUT,DELETE,OPTIONS 
 access-control-allow-origin: * 
 content-type: text/plain 
 date: Thu11 Nov 2021 07:15:15 GMT 
 server: Microsoft-IIS/10.0 
 transfer-encoding: chunked 
 x-powered-by: ASP.NET 

Responses
Code	Description	Links
200	        Success          No links

MichaelG
User
Posts: 1111

Post by MichaelG »

at AspNetMaker2021.Models.ead.GetTableName(String tblVar) in C:\sistemas\iqsis.com.br\wwwroot\.net\estacio\ead\Models\aspnetfn.cs:line 5686

From the stack trace, it was trying to get the problem table but failed. Did you specify the correct table name? Also make sure that the problem table is selected for generation.


Post Reply