コード例 #1
0
        public RetailItem GetItem(string deptName, string itemName)
        {
            Verify.NotNullOrEmpty(deptName, nameof(deptName));
            Verify.NotNullOrEmpty(itemName, nameof(itemName));

            RetailDepartment dept = Departments.FirstOrDefault(o => o.Name.Equals(deptName, StringComparison.OrdinalIgnoreCase));

            VerifyFound("Department", dept);

            RetailItem item = dept.Items.FirstOrDefault(o => o.Name.Equals(itemName, StringComparison.OrdinalIgnoreCase));

            VerifyFound("Item", item);

            if (item.UnitPrice < 0)
            {
                throw new InvalidPriceException(item);
            }

            return(item);
        }
コード例 #2
0
        internal void AddItem(string name, decimal unitPrice)
        {
            var newItem = new RetailItem(name, unitPrice);

            Items.Add(newItem);
        }