private void PrepareModel(MenuItemRecordModel model, MenuItemRecord entity) { Lazy <IMenuItemProvider, MenuItemProviderMetadata> provider = null; var entities = _menuStorage.GetMenuItems(model.MenuId, 0, true).ToDictionary(x => x.Id, x => x); model.Locales = new List <MenuItemRecordLocalizedModel>(); model.AllItems = new List <SelectListItem>(); if (entity != null && ModelState.IsValid) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(entity); model.SelectedCustomerRoleIds = _aclService.GetCustomerRoleIdsWithAccessTo(entity); } if (_menuItemProviders.TryGetValue(model.ProviderName, out provider)) { model.ProviderAppendsMultipleItems = provider.Metadata.AppendsMultipleItems; } // Preset max display order to always insert item at the end. if (entity == null && entities.Any()) { var item = entities .Select(x => x.Value) .Where(x => x.ParentItemId == model.ParentItemId) .OrderByDescending(x => x.DisplayOrder) .FirstOrDefault(); model.DisplayOrder = (item?.DisplayOrder ?? 0) + 1; } // Create list for selecting parent item. var tree = entities.Values.GetTree("EditMenu", _menuItemProviders); tree.Traverse(x => { if (entity != null && entity.Id == x.Value.EntityId) { // Ignore. Element cannot be parent itself. model.TitlePlaceholder = x.Value.Text; } else if (entities.TryGetValue(x.Value.EntityId, out var record) && _menuItemProviders.TryGetValue(record.ProviderName, out provider) && provider.Metadata.AppendsMultipleItems) { // Ignore. Element cannot have child nodes. } else if (!x.Value.IsGroupHeader) { var path = string.Join(" » ", x.Trail.Skip(1).Select(y => y.Value.Text)); model.AllItems.Add(new SelectListItem { Text = path, Value = x.Value.EntityId.ToString(), Selected = entity != null && entity.ParentItemId == x.Value.EntityId }); } }); }
private void UpdateLocales(MenuItemRecord entity, MenuItemRecordModel model) { if (model.Locales != null) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(entity, x => x.Title, localized.Title, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(entity, x => x.ShortDescription, localized.ShortDescription, localized.LanguageId); } } }
public virtual void UpdateMenuItem(MenuItemRecord item) { Guard.NotNull(item, nameof(MenuRecord)); // Prevent inconsistent tree structure. if (item.ParentItemId != 0 && item.ParentItemId == item.Id) { item.ParentItemId = 0; } _menuItemRepository.Update(item); _services.Cache.RemoveByPattern(MENU_PATTERN_KEY); }
public virtual void DeleteMenuItem(MenuItemRecord item, bool deleteChilds = true) { if (item == null) { return; } if (!deleteChilds) { _menuItemRepository.Delete(item); } else { var ids = new HashSet <int> { item.Id }; GetChildIds(item.Id, ids); foreach (var chunk in ids.Slice(200)) { var items = _menuItemRepository.Table.Where(x => chunk.Contains(x.Id)).ToList(); _menuItemRepository.DeleteRange(items); } } _services.Cache.RemoveByPattern(MENU_PATTERN_KEY); void GetChildIds(int parentId, HashSet <int> ids) { var childIds = _menuItemRepository.TableUntracked .Where(x => x.ParentItemId == parentId) .Select(x => x.Id) .ToList(); if (childIds.Any()) { ids.AddRange(childIds); childIds.Each(x => GetChildIds(x, ids)); } } }
public static XmlElement BuildElement(MenuItemRecord menuItemRecord, XmlDocument doc, OracleConnection connection) { XmlElement result = doc.CreateElement("item"); XmlElement prompt = doc.CreateElement("PROMPT"); prompt.AppendChild(doc.CreateTextNode(menuItemRecord.Prompt)); result.AppendChild(prompt); XmlElement apiName = doc.CreateElement("API_NAME"); apiName.AppendChild(doc.CreateTextNode(menuItemRecord.Api)); result.AppendChild(apiName); XmlElement submenu = doc.CreateElement("SUBMENU"); submenu.AppendChild(doc.CreateTextNode(menuItemRecord.SubMenu)); result.AppendChild(submenu); System.IO.MemoryStream memory; try { memory = new System.IO.MemoryStream((byte[])menuItemRecord.Icon.Value); /* OracleQueryBuilder transactionQuery = new QueryBuilder(ifsProperties.AppOwner); * transactionQuery.AddFrom("ESI_SW_TRANSACTION_SYSTEM"); * transactionQuery.AddSelect("PACKAGE", "", "", "", ""); * transactionQuery.AddSelect("API", "", "", "", ""); * transactionQuery.AddSelect("VERSION", "", "", "", ""); * transactionQuery.AddWhere("TRANSACTION", transactionName, "=", "", false, ""); * * using (OracleCommand cmd = connection.CreateCommand()) * { * cmd.CommandText = "select bfile_loc from esi_scanworks_icons where name = :iconName"; * cmd.Parameters.Add("iconName", OracleType.VarChar).Value = iconName; * * using (OracleDataReader reader = cmd.ExecuteReader()) * { * if (reader.Read()) * {ORA * OracleBFile bFile = reader.GetOracleBFile(0); * memory = new System.IO.MemoryStream((byte[])bFile.Value); * bFile.Close(); * } * else * { * throw new Exception(""); * } * } * }*/ } catch (Exception) { System.Drawing.Icon defaultIcon = Icons.Default; memory = new System.IO.MemoryStream(); defaultIcon.Save(memory); } long arrayLength = (long)((4.0d / 3.0d) * memory.Length); // If array length is not divisible by 4, go up to the next // multiple of 4. if (arrayLength % 4 != 0) { arrayLength += 4 - arrayLength % 4; } char[] encodedBuffer = new char[arrayLength]; System.Convert.ToBase64CharArray(memory.ToArray(), 0, (int)memory.Length, encodedBuffer, 0); XmlElement icon = doc.CreateElement("ICON"); icon.AppendChild(doc.CreateTextNode(new string(encodedBuffer))); result.AppendChild(icon); return(result); }