Esempio n. 1
0
        public void RemoveSetting()
        {
            var options = new DbContextOptionsBuilder <CacidbContext>().UseInMemoryDatabase(databaseName: "CACIDB").Options;

            context.Database.EnsureDeleted();

            using (var dbContext = new CacidbContext(options))
            {
                dbContext.UserRole.Add(new UserRole {
                    UserRoleId = 1
                });
                dbContext.SaveChanges();
            }

            using (var dbContext = new CacidbContext(options))
            {
                UserRoleRepository repository = new UserRoleRepository(dbContext);
                var  caseOne = repository.Get().FirstOrDefault(m => m.UserRoleId == 1);
                bool result  = repository.Delete(caseOne);
                Assert.AreEqual(true, result);

                List <UserRole> cases = repository.Get().ToList();
                Assert.AreEqual(0, cases.Count);
            }
        }
Esempio n. 2
0
        protected void OnChangeToAvailable()
        {
            var tmp = SelectedUsedRole;

            if (tmp == null)
            {
                System.Windows.MessageBox.Show("Selecteer a.u.b. een item");
                return;
            }

            var userRole = GetByUserIDAndRoleID(
                SelectedItem.UserID,
                SelectedUsedRole.RoleID);

            if (userRole != null)
            {
                userRoleRepo.Delete(userRole.UserRoleID);

                AvailableRoles.Add(_selectedUsedRole);
                RaisePropertyChanged("AvailableRoles");

                UsedRoles.Remove(_selectedUsedRole);
                RaisePropertyChanged("UsedRoles");
            }
            else
            {
                System.Windows.MessageBox.Show("Onverwachte fout");
            }

            SaveUser();
        }
Esempio n. 3
0
        public async Task Delete([FromBody] UserRole input)
        {
            await CheckPermission();

            var sqlR = new UserRoleRepository();
            await sqlR.Delete(input.Id);

            sqlR.Dispose();
        }
        public async Task <ActionResult> Delete(long id)
        {
            await UserRoleRepository.Delete(id);

            var jsonModel = new JsonModel();

            jsonModel.message      = "删除成功!";
            jsonModel.closeCurrent = false;
            return(Json(jsonModel));
        }
Esempio n. 5
0
        public Task RemoveFromRoleAsync(TUser user, string roleName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            user.Roles.RemoveAll(r => String.Equals(r, roleName, StringComparison.InvariantCultureIgnoreCase));

            _userRoleRepository.Delete(user, roleName);

            return(Task.FromResult(0));
        }
Esempio n. 6
0
 public bool DeleteRoleUser(string roleUserIdStr)
 {
     string[] roleUserIdList = roleUserIdStr.Split(',');
     for (int i = 0; i < roleUserIdList.Length - 1; i++)
     {
         Guid roleUserId = new Guid(roleUserIdList[i]);
         var  RoleUser   = UserRoleRepository.GetQueryable().FirstOrDefault(ur => ur.UserRoleID == roleUserId);
         if (RoleUser != null)
         {
             UserRoleRepository.Delete(RoleUser);
             UserRoleRepository.SaveChanges();
         }
     }
     return(true);
 }
Esempio n. 7
0
        public override void ExecuteCommand(AppSession session, StringRequestInfo requestInfo)
        {
            int role_id = JsonConvert.DeserializeObject <int>(requestInfo.Body);
            UserRoleRepository repository = new UserRoleRepository();
            int result = repository.Delete(role_id);

            if (result == -1)
            {
                session.Send("False");
            }
            else
            {
                session.Send("True");
            }
        }
Esempio n. 8
0
 public bool DeleteUserRole(string userRoleIdStr)
 {
     string[] userRoleIdList = userRoleIdStr.Split(',');
     for (int i = 0; i < userRoleIdList.Length - 1; i++)
     {
         Guid userRoleId = new Guid(userRoleIdList[i]);
         var  UserRole   = UserRoleRepository.GetQueryable().FirstOrDefault(ur => ur.UserRoleID == userRoleId);
         if (UserRole != null)
         {
             UserRoleRepository.Delete(UserRole);
             UserRoleRepository.SaveChanges();
         }
     }
     return(true);
 }
Esempio n. 9
0
        public void TestGetRoles()
        {
            /*
             * UserRepository.Add(user);
             * Role role = roleRepository.getBySlug("listner");
             * UserRoleRepository.Add(new UserRole { UserId = user.UserId, User = user, Role = role, RoleId = role.RoleId });
             */

            userRepository.Add(user);
            roleRepository.Add(role);
            userRole = new UserRole {
                UserId = user.UserId, User = user, Role = role, RoleId = role.RoleId
            };
            userRoleRepository.Add(userRole);
            Assert.AreEqual(1, userRepository.GetRoles(user).Count);
            userRoleRepository.Delete(userRole);
            roleRepository.Delete(role);
            userRepository.Delete(user);
        }
Esempio n. 10
0
        public async Task <int> Update([FromBody] DTOUserWithRoles dtoUserRoles)
        {
            if (dtoUserRoles.Roles != null)
            {
                userRoleRepo.Delete(dtoUserRoles.User.Id);

                foreach (var item in dtoUserRoles.Roles)
                {
                    DTOUserRole dtoUserRole = new DTOUserRole();
                    dtoUserRole.RoleId = item.Id;
                    dtoUserRole.Role   = item;
                    dtoUserRole.UserId = dtoUserRoles.User.Id;
                    dtoUserRole.User   = dtoUserRoles.User;

                    userRoleRepo.Create(dtoUserRole);
                }
            }
            return(await userRepo.Update(dtoUserRoles.User));
        }
Esempio n. 11
0
        public async void Del_Success()
        {
            var sqlR = new UserRoleRepository();
            var e    = new UserRole
            {
                Name        = Guid.NewGuid().ToString(),
                Permissions = 123
            };
            var id = await sqlR.Add(new UserRoleRepository.UserRoleUi {
                Role = e
            });

            var results = await sqlR.GetAll(0, 10000);

            await sqlR.Delete(results.Data.LastOrDefault().Role.Id);

            var resultsAfterDel = await sqlR.GetAll(0, 10000);

            Assert.True(results.Data.ToArray().Length > resultsAfterDel.Data.ToArray().Length);
        }
Esempio n. 12
0
        private async Task RemoveRoleFromUser(UserRole userRole)
        {
            if (userRole == null)
            {
                return;
            }

            using (var uow = new UnitOfWork(Context))
            {
                var repo = new UserRoleRepository(uow);

                await repo.Delete(userRole.UserRoleId);
            }

            var userRoleCache = new UserRoleCache(Cache);

            await userRoleCache.InvalidateUserRoleCache(userRole.UserId);

            //await SendRoleUpdatedEvent(userRole, false);
        }
Esempio n. 13
0
        public void SubmitForm(UserInputDto userInputDto, string[] roleIds, string keyValue)
        {
            User user = new User();

            if (!string.IsNullOrEmpty(keyValue))
            {
                var      id          = Convert.ToInt64(keyValue);
                string[] includePath = { "Company", "Department", "Duty", "UserRoles", "UserRoles.Role", "UserRoles.User" };
                user = userRepository.Get(id, includePath);
                AutoMapper.Mapper.Map <UserInputDto, User>(userInputDto, user);
                user.LastModificationTime = DateTime.Now;
                userRepository.Update(user);
            }
            else
            {
                AutoMapper.Mapper.Map <UserInputDto, User>(userInputDto, user);
                user.Id            = IdWorkerHelper.GenId64();
                user.DeletedMark   = false;
                user.CreationTime  = DateTime.Now;
                user.CreatorUserId = 1;
                user.SecretKey     = Md5.md5(Common.CreateNo(), 16).ToLower();
                user.Password      = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userInputDto.Password, 32).ToLower(), user.SecretKey).ToLower(), 32).ToLower();
                userRepository.Add(user);
            }

            #region  除用户所属角色,再添加用户角色
            userRoleRepository.Delete(new Specification <UserRole>(p => p.UserId == Convert.ToInt64(keyValue)));
            List <UserRole> userRoles = new List <UserRole>();
            for (var i = 0; i < roleIds.Length; i++)
            {
                var userRole = new UserRole();
                userRole.UserId      = user.Id;
                userRole.RoleId      = Convert.ToInt64(roleIds[i]);
                userRole.DeletedMark = true;
                userRoles.Add(userRole);
            }
            userRoleRepository.Add(userRoles);
            #endregion
        }
        public void UserRoleCRUDTest()
        {
            var context = new NoodleDbContext("NoodleDb");

            IUserRoleRepository service = new UserRoleRepository(context);

            var ID_        = Guid.NewGuid();
            var USER_GUID_ = Guid.NewGuid();
            var ROLE_GUID_ = Guid.NewGuid();

            var record = new UserRole
            {
                Id       = ID_,
                UserGuid = USER_GUID_,
                RoleGuid = ROLE_GUID_
            };

            service.Create(record);

            record.UserGuid = Guid.NewGuid();
            record.RoleGuid = Guid.NewGuid();

            service.Update(record);

            var record2 = service.GetById(ID_);

            Assert.AreEqual(record.Id, record2.Id);
            Assert.AreEqual(record.RoleGuid, record2.RoleGuid);
            Assert.AreEqual(record.UserGuid, record2.UserGuid);

            service.Delete(record.Id);

            var record3 = service.GetById(ID_);

            Assert.IsNull(record3);
        }
Esempio n. 15
0
 public void Delete(int id)
 {
     UserRoleRepository.Delete(id);
 }
Esempio n. 16
0
        /// <summary>
        /// 更新基本信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public OperationResult Update(UpdateUserModel model)
        {
            var entity = Users.FirstOrDefault(t => t.Id == model.Id);

            //entity.FullName = model.FullName;
            entity.Tel        = model.Phone;
            entity.Enabled    = model.Enabled;
            entity.ModifyId   = model.ModifyId;
            entity.ModifyBy   = model.ModifyBy;
            entity.ModifyTime = DateTime.Now;

            #region Update User Role Mapping
            var oldRoleIds       = entity.UserRoles.Where(t => t.IsDeleted == false).Select(t => t.RoleId).ToList();
            var newRoleIds       = model.SelectedRoleList.ToList();
            var intersectRoleIds = oldRoleIds.Intersect(newRoleIds).ToList();    // Same Ids
            var removeIds        = oldRoleIds.Except(intersectRoleIds).ToList(); // Remove Ids
            var addIds           = newRoleIds.Except(intersectRoleIds).ToList(); // Add Ids
            foreach (var removeId in removeIds)
            {
                //更新状态->物理删除0321
                // var userRole = UserRoles.FirstOrDefault(t => t.UserId == model.Id && t.RoleId == removeId);
                //userRole.IsDeleted = true;
                //userRole.ModifyId = model.ModifyId;
                //userRole.ModifyBy = model.ModifyBy;
                //userRole.ModifyTime = DateTime.Now;

                UserRoleRepository.Delete(t => t.UserId == model.Id && t.RoleId == removeId);
            }
            foreach (var addId in addIds)
            {
                var userRole = UserRoles.FirstOrDefault(t => t.UserId == model.Id && t.RoleId == addId);
                // 已有该记录,更新状态
                if (userRole != null)
                {
                    userRole.IsDeleted  = false;
                    userRole.ModifyId   = model.ModifyId;
                    userRole.ModifyBy   = model.ModifyBy;
                    userRole.ModifyTime = DateTime.Now;
                    UserRoleRepository.Update(userRole);
                }
                // 插入
                else
                {
                    entity.UserRoles.Add(new UserRole {
                        UserId     = model.Id,
                        RoleId     = addId,
                        CreateId   = model.CreateId,
                        CreateBy   = model.CreateBy,
                        CreateTime = DateTime.Now,
                        ModifyId   = model.ModifyId,
                        ModifyBy   = model.ModifyBy,
                        ModifyTime = DateTime.Now
                    });
                }
            }

            #endregion

            UserRepository.Update(entity);
            return(new OperationResult(OperationResultType.Success, "更新成功"));
        }