This is my Table:Statistics
Id,Depth,RefreshCounter
Sample Records:
Id Depth RefreshCounter
1 1 1
2 1 0
3 1 0
4 1 0
Now what i need to do is whenever i am refreshing the page i need to increment this refreshcounter value by 1 in Database table with Depth 1.
I am calling this method like this on load of my view page:
@Html.Action("IncrementRefreshcounter", "Statistics", new { id = 1}) //for eg:1,2,3,4
Here is my code which does this:
[ChildActionOnly]
public ActionResult IncrementRefreshcounter(int id)
{
using ( var context = new MyDBContext())
{
//at each page refresh i would be passing different id to my controller from view.for eg 1,2,3,4
var data=context.Statistics.where(x=>x.Depth==1 && r.Id==id).FirstorDefualt();
context.RefreshCounter++;//Increment here RefreshCounter.
context.SaveChangesAsync();
return PartialView("xxx")
}
}
I am calling this method when my View Loads.Problem is when i run my Application first time and calling this method it successfully updated RefreshCounter by 1 but after that whenever i refresh my page and calling this method it never updated RefreshCounter for any records with Depth=1.
In my sample Records you can see that Id 1 with Depth 1 have refresh counter with value 1 because it was the first time when i have run my application and it has successfully updated that value but after that it is never updating any value for eg:Id 2 Depth 1
It is incrementing only 1 time RefreshCounter but after that it never increments that variable.
Can anybody tell me what the problem is SaveChangesAsync ??