コード例 #1
0
        public static void ChooseOperationForGoodsRepository(IGoodsRepository goodsRepository, OperationForGoodsRepository goodsRepositoryOperation)
        {
            switch (goodsRepositoryOperation)
            {
            case OperationForGoodsRepository.ShowAll:
                ShowAllGoods(goodsRepository.Get());
                break;

            case OperationForGoodsRepository.ShowById:
                Console.WriteLine("Enter good Id: ");
                if (int.TryParse(Console.ReadLine(), out var getGoodId))
                {
                    Console.WriteLine(goodsRepository.Get(getGoodId));
                }
                break;

            case OperationForGoodsRepository.Add:
                Good goodToAdd = CreateGoodToAdd();
                goodsRepository.Add(goodToAdd);
                Console.WriteLine("New good added");
                break;

            case OperationForGoodsRepository.Update:

                Good goodToUpdate = null;
                Console.Write("Enter good Id to update: ");
                if (int.TryParse(Console.ReadLine(), out var getGoodIdToUpdate))
                {
                    goodToUpdate = goodsRepository.Get(getGoodIdToUpdate);
                }
                var fieldToUpdate = ShowGoodUpdateMenu();
                ChooseFieldToUpdate(goodToUpdate, fieldToUpdate);

                goodsRepository.Update(goodToUpdate);
                Console.WriteLine("Good updated");
                break;

            case OperationForGoodsRepository.Delete:
                Console.WriteLine("Enter good Id: ");
                if (int.TryParse(Console.ReadLine(), out var deleteGoodId))
                {
                    goodsRepository.Delete(deleteGoodId);
                    Console.WriteLine("Good deleted");
                }
                break;

            case OperationForGoodsRepository.ShowMaxQuantityGood:
                var goodMaxQuantity = goodsRepository.GetMaxQuantityGood();
                Console.WriteLine($" Max quantity Good: Name: {goodMaxQuantity.Name} Quantity: {goodMaxQuantity.Quantity}");
                break;

            case OperationForGoodsRepository.ShowMinQuantityGood:
                var goodMinQuantity = goodsRepository.GetMinQuantityGood();
                Console.WriteLine($" Min quantity Good: Name: {goodMinQuantity.Name} Quantity: {goodMinQuantity.Quantity}");
                break;

            case OperationForGoodsRepository.ShowMaxCostGood:
                var goodMaxCost = goodsRepository.GetMaxCostGood();
                Console.WriteLine($" Max cost Good: Name: {goodMaxCost.Name} Cost: {goodMaxCost.Cost}");
                break;

            case OperationForGoodsRepository.ShowMinCostGood:
                var goodMinCost = goodsRepository.GetMinCostGood();
                Console.WriteLine($" Min cost Good: Name: {goodMinCost.Name} Cost: {goodMinCost.Cost}");
                break;

            case OperationForGoodsRepository.ShowGoodsByType:
                IEnumerable <Good> goodsByTypeId = null;
                Console.Write("Enter type Id: ");
                if (int.TryParse(Console.ReadLine(), out var typeId))
                {
                    goodsByTypeId = goodsRepository.GetGoodsByType(typeId);
                }
                ShowAllGoods(goodsByTypeId);
                break;

            case OperationForGoodsRepository.ShowGoodsBySupplier:
                IEnumerable <Good> goodsBySupplier = null;
                Console.Write("Enter supplier Id: ");
                if (int.TryParse(Console.ReadLine(), out var supplierId))
                {
                    goodsBySupplier = goodsRepository.GetGoodsBySupplier(supplierId);
                }
                ShowAllGoods(goodsBySupplier);
                break;

            case OperationForGoodsRepository.ShowGoodsByPassedDays:
                IEnumerable <Good> goodsByPassedDays = null;
                Console.Write("Enter number of days: ");
                if (int.TryParse(Console.ReadLine(), out var numberOfDays))
                {
                    goodsByPassedDays = goodsRepository.GetGoodsByPassedDays(numberOfDays);
                }
                ShowAllGoods(goodsByPassedDays);
                break;

            case OperationForGoodsRepository.ShowGoodsByPassedMaxDays:
                var theOldestGood = goodsRepository.GetTheOldestGood();
                Console.WriteLine($" The oldest Good: Name: {theOldestGood.Name} DeliveryDate: {theOldestGood.DeliveryDate}");
                break;

            case OperationForGoodsRepository.ShowAverageGoodsQuantityByType:
                goodsRepository.GetAvgGoodsQuantityByType();
                break;

            default:
                Environment.Exit(0);
                break;
            }
        }