Question: I am calling a method which is

```
public IHttpActionResult GetData(int id) 
{
  ...
  List<MyData> dataList = getArrayOfRecords();
  return Ok(dataList .ToList());
}

```

In my calling method, I am trying to recast the returned array as followed

```
List<MyData> result = (List<MyData> result)myFunction.get(1);

```

I get the following error

```
"Unable to cast object of type 'System.Web.Http.Results.OkNegotiatedContentResult" 

```

Any help is appreciated. Thanks

Answer: 
> 
> Can I have something like a schedule plan in MySQL to delete those records? or even in PHP?
> 
> 
> 

Usually this sort of thing is done using your server's "cron" feature (or "Scheduled Tasks" if your server is running Windows). You can write a PHP script that clears these abandoned carts when run, and configure your server to execute that PHP script at regular intervals.

MySQL also has an "Event Scheduler" feature; I don't think that gets used very often, but it is an option.
> 
> ...so if user close the payment gateway browser's tab, wanted items are reduced from stock items count and never returns.
> 
> 
> 

This is the wrong way to look at this problem. Consider these scenarios:

* User accidentally closes their browser, re-opens it, and tries to finish purchasing
* User loses internet access and cannot finish purchasing... browser isn't closed

While it is possible to use the Beacon API in newer browsers to send an update when a browser is closed, for these reasons it's a bad idea.

You have two general options:

Option 1: Track the user/cart activity
--------------------------------------

Every time the user does something meaningful on the site, update their last active time on a record for their cart. If a user is still browsing the site and they have a product in their cart, keep it reserved there until the sale is complete or until they are no longer active for some period of time. For example, if they haven't been on the page in 15 minutes, release the reservation for the product. (Be prepared to reserve it again if they come back and the product is still available.)

Option 2: Don't reserve until purchase
--------------------------------------

Keep the item in-stock until it's actually bought. If at the time of purchase the product is no longer available, let the user know.

Which of these options you choose depends on your business conditions and the sort of stuff you're selling.