Пример #1
0
        private async void buttonAddOrder_Click(object sender, System.EventArgs e)
        {
            if (!VerifyOrdersValues(out var summ, out var payment))
            {
                return;
            }
            if (selectedClientsRow[0] == null)
            {
                return;
            }
            var selectedClientRow = selectedClientsRow[0];
            var workers           = await _workerRepository.GetWorkersWhoRole("archivarius");

            foreach (var worker in workers)
            {
                if (worker.Orders != null)
                {
                    if (worker.Orders.Count < buff)
                    {
                        buff            = worker.Orders.Count;
                        _chosenWorkerId = worker.Id;
                    }
                }
                else
                {
                    buff            = 0;
                    _chosenWorkerId = worker.Id;
                }
            }

            var order = new Models.Orders()
            {
                ClientId      = Convert.ToInt32(selectedClientRow.Cells[0].Value),
                Payment       = Convert.ToInt32(summ),
                PaymentIsDone = Convert.ToInt32(payment),
                TimeCreated   = DateTime.Now,
                WorkerId      = _chosenWorkerId
            };

            NormalizeTables();
            await _ordersRepository.CreateOrder(order);

            await UpdateDataGridViewOrders(Convert.ToInt32(textBoxIdClient.Text));
        }