public void SendCall(Call call) { Random random = new Random(); var operators = _db.Operators.Where(x => x.Id > 0); var calls = GenerateCalls(call.Length); var threads = new List <Thread>(); foreach (var @operator in operators) { var thread = new Thread(() => { @operator.Activate(); }); threads.Add(thread); thread.Start(); } Task.Run(() => { for (var idx = 0; idx < 100; ++idx) { if (operators.All(_ => _.StatusId == 1)) { Console.WriteLine("All operators are busy"); } else { var @operator = operators.FirstOrDefault(_ => _.StatusId == 2); if (@operator == null) { Console.WriteLine("All operators are busy"); } else { @operator.StatusId = 1; _db.SaveChanges(); var activeCall = calls.Where(x => x.IsActive == true).FirstOrDefault(); activeCall.ManagingByUserId = @operator.Id; @operator.Answer(activeCall.Length); activeCall.IsActive = false; Clients.All.SendAsync("SendCall", activeCall); @operator.StatusId = 2; _db.SaveChanges(); } } Thread.Sleep(random.Next(1000, 5000)); } }); Console.ReadLine(); }
public ActionResult StopEmulation() { var ops = _db.Operators; foreach (var o in ops) { o.StatusId = 2; } _db.SaveChanges(); return(RedirectToAction("Index")); }
public int Complete() { return(_context.SaveChanges()); }