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);
}
}
}
}
}
}