Exemplo n.º 1
0
        public void EnableOrDisabledAll(int profileId, bool ativar, long userId)
        {
            var profileForMenus = _menuRepository.GetPorProfile(profileId);

            if (ativar == false)
            {
                var delete = profileForMenus
                             .Where(w => w.Id != 0)
                             .ToList();

                foreach (var pm in delete)
                {
                    _menuRepository.RemoveProfileForMenu(pm.Id, userId);
                }
            }
            else
            {
                var create = profileForMenus
                             .Where(w => w.Id == 0)
                             .Select(s => s.Menu)
                             .ToList();

                var insertList = create.Select(item => new ProfileForMenu
                {
                    ProfileId = profileId,
                    MenuId    = item.Id
                }).ToList();

                if (insertList.Any())
                {
                    _menuRepository.AddRangeProfileForMenu(insertList, userId);
                }
            }
        }