Ejemplo n.º 1
0
        public async Task <bool> Update(IEnumerable <AccountAdmin> currentAccountAdmins, IEnumerable <AccountAdmin> newAccountAdmins)
        {
            _context.Set <AccountAdmin>().RemoveRange(currentAccountAdmins.Except(newAccountAdmins, x => x.UserId));
            _context.Set <AccountAdmin>().AddRange(newAccountAdmins.Except(currentAccountAdmins, x => x.UserId));
            await _context.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Update(IEnumerable <UserGate> currentGateUsers, IEnumerable <UserGate> newGateUsers)
        {
            _context.Set <UserGate>().RemoveRange(currentGateUsers.Except(newGateUsers, x => x.UserId));
            _context.Set <UserGate>().AddRange(newGateUsers.Except(currentGateUsers, x => x.UserId));

            await _context.SaveChangesAsync();

            foreach (var newGateUser in newGateUsers)
            {
                var userGate = _context.UserGates.FirstOrDefault(x => x.UserId == newGateUser.UserId && x.GateId == newGateUser.GateId);
                userGate.AccessRight = newGateUser.AccessRight;
                userGate.AdminRight  = newGateUser.AdminRight;
                userGate.ModifiedBy  = newGateUser.ModifiedBy;
                userGate.MoidifiedAt = newGateUser.MoidifiedAt;
                _context.UserGates.Update(userGate);
            }

            await _context.SaveChangesAsync();

            return(true);
        }