public async Task StartConsoleLoop()
        {
            while (true)
            {
                try
                {
                    Console.Clear();
                    await _printCharacteristicService.PrintAll();

                    PrintMenu();

                    var menuTab = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

                    switch (menuTab)
                    {
                    case 1:
                        await _crudCharacteristicService.Add();

                        break;

                    case 2:
                        await _crudCharacteristicService.Delete();

                        break;

                    case 3:
                        await _crudCharacteristicService.Update();

                        break;

                    case 4:
                        return;
                    }
                }
                catch (ValidationException e)
                {
                    Console.WriteLine($"Validation error. Message: {e.Message}");
                    Console.ReadKey();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadKey();
                }
            }
        }
Пример #2
0
        public async Task StartConsoleLoop()
        {
            while (true)
            {
                try
                {
                    Console.Clear();
                    await _printProductService.PrintAll();

                    PrintMenu();

                    var menuTab = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

                    switch (menuTab)
                    {
                    case 1:
                    {
                        Console.WriteLine("Enter Id of product");
                        var productId = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

                        if (await _productManager.GetById(productId) == null)
                        {
                            throw new InvalidOperationException();
                        }

                        _productConsoleService.ProductId = productId;

                        await _productConsoleService.StartConsoleLoop();
                    }
                    break;

                    case 2:
                    {
                        await _crudProductService.Add();
                    }
                    break;

                    case 3:
                    {
                        await _crudProductService.Update();
                    }
                    break;

                    case 4:
                    {
                        await _crudProductService.Delete();
                    }
                    break;

                    case 5:
                        return;
                    }
                }
                catch (ValidationException e)
                {
                    Console.WriteLine($"Validation error. Message: {e.Message}");
                    Console.ReadKey();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadKey();
                }
            }
        }