Пример #1
0
        public void Synchronize(IEnumerable <string> menuList, long userId)
        {
            IList <Menu> entityList = menuList
                                      .Select(menu => menu.Split('|'))
                                      .Select(splitMenu => new Menu
            {
                Id   = Convert.ToInt32(splitMenu[0]),
                Nome = splitMenu[1].Trim()
            })
                                      .ToList();

            IList <Menu> menus = _menuRepository
                                 .GetAllWithDapper()
                                 .ToList();

            var menusNaoExistentes = entityList
                                     .Where(w => !menus.Select(s => s.Id).Contains(w.Id))
                                     .ToList();

            var menusExistentes = entityList
                                  .Where(w => menus.Select(s => s.Id).Contains(w.Id))
                                  .ToList();

            var menusDelete = menus
                              .Where(w => !entityList.Select(s => s.Id).Contains(w.Id))
                              .ToList();

            if (menusNaoExistentes.Any())
            {
                _menuRepository.AddRange(menusNaoExistentes, userId);
            }

            if (menusExistentes.Any())
            {
                _menuRepository.UpdateList(menusExistentes, userId);
            }

            foreach (var menu in menusDelete)
            {
                _menuRepository.Remove(menu.Id, userId);
            }
        }
Пример #2
0
 public void AddRange(IEnumerable <Menu> menu)
 {
     _menuRepository.AddRange(menu);
 }