I got a issue: I am lopping through a webservice and saving data on the database.
My code works but the issue is that wen i call it from ajax on layout chrome its crashing.
Controller:
[HttpPost]
public JsonResult seen()
{
var us = User.Identity.Name;
var loginuserID = db.workers.Where(r => r.UserId == us).FirstOrDefault();
var Ids = db.Clients.Select(r => r.login).ToList();
List<apicli> list1 = new List<apicli>();
List<notification> notifications = new List<notification>();
var notificat = new notification();
var clie = new apicli();
var sales1 = new sales();
List<sales> sales = new List<sales>();
foreach (var item1 in Ids)
{
var client = new WebClient();
var text = client.DownloadString("http://website.com/api-v2/mt4_prices.php?mode=mt4_trades&s="+item1+"&name=username&pass=password");
var wclients = JsonConvert.DeserializeObject<dynamic>(text);
var data = wclients;
var deposit = wclients;
if (!db.sales.Any(a => a.Ticket == sales1.Ticket && a.CMD == sales1.CMD))
{
if (sales1.CMD == 6)
{
notifications.Add(notificat);
db.SaveChanges();
}
}
}
return new JsonResult();
}
and my ajax call on the layout its:
<script>
function getEvents() {
$.ajax({
dataType: 'json',
type: "POST",
url: '@Url.Action("seen","Ajax")',
cache: false,
async: false,
error: function (xhr, status, error) {
},
});
}
</script>