Ejemplo n.º 1
0
 public T SaveNew <T>(T entity, string userId = null) where T : class
 {
     _context.Set <T>().Add(entity);
     if (!string.IsNullOrEmpty(userId))
     {
         _context.SaveChanges(userId);
     }
     else
     {
         _context.SaveChanges();
     }
     return(entity);
 }
        public async Task UpdatePermissionGroup(GroupViewModel groupViewModel)
        {
            if (groupViewModel != null && groupViewModel.PermissionViewModelList != null && groupViewModel.PermissionViewModelList.Count() > 0)
            {
                var permissionIds = groupViewModel.PermissionViewModelList.Select(x => x.Id).ToList();

                _context.PermissionGroups.RemoveRange(_context.PermissionGroups.Where(x => x.GroupId == groupViewModel.Id));
                foreach (var permissionViewModel in groupViewModel.PermissionViewModelList.Where(x => x.IsSelected))
                {
                    _context.PermissionGroups.Add(new PermissionGroup()
                    {
                        GroupId = groupViewModel.Id, PermissionId = permissionViewModel.Id
                    });
                }
                _context.SaveChanges();
            }
        }