Example #1
0
        public CreateGood ReadGood(List <Component> componentInfo)
        {
            var goodComponents = new List <GoodComponent>();

            GoodComponent chosenComponent;
            int           chosenComponentQuantity;

            var componentsMenu = new Menu();

            componentsMenu.Add("Choose component", () => {
                chosenComponent = new GoodComponent
                {
                    Id = componentInfo[ReadNumberWithHint("Enter a component number: ",
                                                          minBound: 1, maxBound: componentInfo.Count) - 1].Id
                };
                chosenComponentQuantity = ReadNumberWithHint("Enter the quantity of the component: ",
                                                             minBound: 1, maxBound: int.MaxValue);
                chosenComponent.Quantity = chosenComponentQuantity;
                goodComponents.Add(chosenComponent);
            });

            var goodsReady = false;

            componentsMenu.Add("Done", () => goodsReady = true);

            while (!goodsReady)
            {
                PrintTable(componentInfo);
                PrintMenu(componentsMenu);

                var chosenOption = ReadNumberWithHint("Choose an option:",
                                                      minBound: 1, maxBound: componentsMenu.Options.Count);
                componentsMenu.ExecuteOption(chosenOption - 1);
            }

            decimal unitPrice          = ReadPriceWithHint("Enter an unit price of the good: ");
            string  description        = ReadLineWithHint("Enter a description of the good: ");
            int     quantityTypeNumber = ReadNumberWithHint("Enter a number of quantity type, where kilogram - 1, litre - 2, piece - 3 ",
                                                            1, Enum.GetNames(typeof(QuantityType)).Length);

            return(new CreateGood
            {
                UnitPrice = unitPrice,
                QuantityType = (QuantityType)quantityTypeNumber,
                Components = goodComponents,
                Description = description
            });
        }
 public static GoodComponentDto ToDto(GoodComponent goodComponent) => new GoodComponentDto
 {
     Id       = goodComponent.Id,
     Quantity = goodComponent.Quantity
 };