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); } }
public ActionResult Edit(UserRoleModel model) { var result = new JsonModel(); var opType = OperationType.Insert; UserRole role = null; if (model.Id > 0) { role = UserRoleRepository.Get(model.Id); if (role == null) { result.msg = $"找不到id为{0}的角色"; return(Json(result)); } opType = OperationType.Update; } else { role = new UserRole(); } Mapper.Map(model, role); UserRoleSvc.SaveList(role, model.MenuIds); LogRepository.Insert(TableSource.UserRole, opType, role.Id); result.code = JsonModelCode.Succ; ShowSuccMsg("保存成功!"); return(Json(result)); }
public UserResponseBO Authenticate(UserBO userBO) { using (var db = new dbGSCasinoContext()) { UserAuthRepository userAuthRepository = new UserAuthRepository(); TblUserAuth userAuth = userAuthRepository.Get(userBO, db); UserInfoRepository userInfoRepository = new UserInfoRepository(); TblUserInfo userInfo = userInfoRepository.Get(userAuth, db); UserWalletRepository userWalletRepository = new UserWalletRepository(); List <UserWalletBO> userWallet = userWalletRepository.GetBO(userAuth, db); UserRoleRepository userRoleRepository = new UserRoleRepository(); TblUserRole userRole = userRoleRepository.Get(userAuth, db); UserResponseBO userAuthResponse = new UserResponseBO(); userAuthResponse.UserInfo = userInfo; userAuthResponse.UserWallet = userWallet; userAuthResponse.UserAuth = userAuth; userAuthResponse.UserRole = userRole; return(userAuthResponse); } }
public void GetUserRole() { // test Get All UserRoleRepository repository = new UserRoleRepository(context); List <UserRole> cases = repository.Get().ToList(); Assert.AreEqual(3, cases.Count); }
public ActionResult Edit(long id, string reUrl) { ViewBag.ReUrl = reUrl ?? Url.Action("Index"); var model = new UserRoleModel(); if (id != 0) { var role = UserRoleRepository.Get(id); if (role == null) { ShowErrorMsg(); return(Redirect(ViewBag.ReUrl)); } Mapper.Map(role, model); var lstMenuId = UserRole2MenuRepository.GetLstMenuId(role.Id); model.MenuIds = JsonConvert.SerializeObject(lstMenuId); } return(View(model)); }
public UserRole Get(int id) { return(UserRoleRepository .Get(r => r.Id == id && !r.IsDeleted)); }