Samba.Domain.Models.Menus.MenuItem.GetPortion C# (CSharp) Method

GetPortion() private method

private GetPortion ( string portionName ) : MenuItemPortion
portionName string
return MenuItemPortion
        internal MenuItemPortion GetPortion(string portionName)
        {
            foreach (var portion in Portions)
            {
                if (portion.Name == portionName)
                    return portion;
            }
            if (string.IsNullOrEmpty(portionName) && Portions.Count > 0) return Portions[0];
            throw new Exception("Porsiyon Tanımlı Değil.");
        }

Usage Example

Example #1
0
        public void UpdateMenuItem(int userId, MenuItem menuItem, string portionName, string priceTag, int quantity, string defaultProperties)
        {
            MenuItemId = menuItem.Id;
            MenuItemName = menuItem.Name;
            var portion = menuItem.GetPortion(portionName);
            Debug.Assert(portion != null);
            UpdatePortion(portion, priceTag, menuItem.VatTemplate);
            Quantity = quantity;
            _selectedQuantity = quantity;
            PortionCount = menuItem.Portions.Count;
            CreatingUserId = userId;
            CreatedDateTime = DateTime.Now;

            if (!string.IsNullOrEmpty(defaultProperties))
            {
                foreach (var menuItemPropertyGroup in menuItem.PropertyGroups)
                {
                    var properties = defaultProperties.Split(',');
                    foreach (var defaultProperty in properties)
                    {
                        var property = defaultProperty.Trim();
                        var pQuantity = 1;
                        if (defaultProperty.Contains("*"))
                        {
                            var parts = defaultProperty.Split(new[] { '*' }, 1);
                            if (!string.IsNullOrEmpty(parts[0].Trim()))
                            {
                                property = parts[0];
                                int.TryParse(parts[1], out pQuantity);
                            }
                            else continue;
                        }
                        var defaultValue = menuItemPropertyGroup.Properties.FirstOrDefault(x => x.Name == property);
                        if (defaultValue != null)
                        {
                            for (int i = 0; i < pQuantity; i++)
                            {
                                ToggleProperty(menuItemPropertyGroup, defaultValue);
                            }
                        }
                    }
                }
            }
        }