public void Create(CreateMenuItemsViewModel menuItem)
        {
            if (menuItem.Items.GroupBy(p => p.Name).Select(p => p.Count()).Any(p => p > 1))
            {
                AddError("Duplicate item");
                return;
            }
            var itens = new MenuItem[menuItem.Items.Length];

            for (var index = 0; index < menuItem.Items.Length; index++)
            {
                itens[index] = new MenuItem(menuItem.Items[index].Name, menuItem.Items[index].Description, menuItem.Items[index].UrlImage, menuItem.Items[index].Value, menuItem.IdMenu);
            }

            if (!IsError() && _menuItemRepository.ExistMenuItemNameDapper(menuItem.IdMenu, itens.Select(p => p.Name).ToArray()))
            {
                AddError("Menu Item already exists");
            }

            _menuItemRepository.CreateRange(itens);

            Commit();
        }
예제 #2
0
 public Task <ObjectResult> Create(CreateMenuItemsViewModel createMenuItemViewModel)
 {
     _menuItemApplication.Create(createMenuItemViewModel);
     return(CreateResponse(null));
 }