public ActionResult GetAll()
        {
            List <WorkerViewModel> workers = new List <WorkerViewModel>();

            foreach (var worker in repo.GetAll())
            {
                string name = repo.GetNameCompanyById(worker.CompanyId);
                workers.Add(CopyToViewModel(worker, name));
            }

            return(View(workers));
        }
Пример #2
0
        public void Distribute()
        {
            activeRequests = requestRepository.GetAll().Where(r => !r.IsComplete);
            workers        = workerRepository.GetAll();
            activeSettings = settingsRepository.Get(0);

            void CheckTakenRequests()
            {
                foreach (var request in TakenRequest)
                {
                    if (DateTime.Now.Ticks >= request.ExecutedDate)
                    {
                        request.IsComplete = true;
                        var worker = workers.SingleOrDefault(x => x.WorkingRequestId == request.Id);
                        worker.WorkingRequestId = null;
                        SaveChanges(request, worker);
                        Debug.WriteLine($"{worker.Name} закончил с запросом {request.Id}!");
                    }
                }
            }

            void DistributeForFreeWorkers()
            {
                foreach (var worker in FreeWorkers)
                {
                    var request = NotTakenRequest.FirstOrDefault();
                    if (request is null)
                    {
                        break;
                    }
                    if (!worker.CheckRequest(request, activeSettings))
                    {
                        continue;
                    }
                    else
                    {
                        Debug.WriteLine($"Запрос {request.Id} подходит {worker.Name}!");
                        Random random = new Random();
                        request.TakenDate       = DateTime.Now.Ticks;
                        request.Executor        = $"{worker.Position} {worker.Name}";
                        request.ExecutedDate    = DateTime.Now.AddSeconds(random.Next(activeSettings.ExecuteTimeLimitLeft, activeSettings.ExecuteTimeLimitRight)).Ticks;
                        worker.WorkingRequestId = request.Id;
                        SaveChanges(request, worker);
                    }
                }
            }

            CheckTakenRequests();
            DistributeForFreeWorkers();

            Debug.WriteLine($"Запросов в очереди: {NotTakenRequest.Count()}");
            if (FreeWorkers.Count() == 0)
            {
                Debug.WriteLine($"Нет свободных сотрудников!");
            }
        }
Пример #3
0
        public List <Worker> GetAll()
        {
            var users = WorkerRepository.GetAll();

            if (users == null)
            {
                throw new BadRequestException(ErrorMessages.UserNoEncontrado);
            }

            var result     = new List <Worker>();
            var enumerator = users.GetEnumerator();

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }
            return(result);
        }
Пример #4
0
 public List <Worker> GetAll()
 {
     return(WorkerRepository.GetAll().ToList());
 }
Пример #5
0
 public async Task <IEnumerable <Worker> > GetAllWorkers()
 {
     return(await _workerRepository.GetAll());
 }