private static int DeleteRecordsByController(Controller controller) { int ret = 0; using (TransactionalDbClient tc = ionixFactory.CreateTransactionalDbClient()) { ControllerRepository controllerRepository = new ControllerRepository(tc.Cmd); ActionRepository actionRepository = new ActionRepository(tc.Cmd); List <Server.Models.Action> controllerActions = actionRepository.SelectByControllerId(controller.Id).ToList(); if (!controllerActions.IsEmptyList()) { List <int> controllerActionIds = new List <int>(controllerActions.Count); controllerActions.ForEach((aa) => controllerActionIds.Add(aa.Id)); //RoleControllerAction Siliniyor. RoleActionRepository roleControllerActionRepository = new RoleActionRepository(tc.Cmd); ret += roleControllerActionRepository.DeleteByControllerActionIds(controllerActionIds); //controllerAction Siliniyor. ret += actionRepository.DeleteByControllerId(controller.Id); } //controller Siliniyor. ret += controllerRepository.Delete(controller); tc.Commit(); } return(ret); }
public string LoginUser() { string result = ""; string userName = Request["userName"] + ""; string password = Request["password"] + ""; try { var user = new UserRepository().Get(userName, password); if (user == null || user.ID == 0) throw new Exception(Resources.Messages.Login_IncorrectUsername); if (user.RecordStatus == (byte)RecordStatus.Inactive) throw new Exception(Resources.Messages.Login_InactiveUser); if (user.RecordStatus == (byte)RecordStatus.Blocked) throw new Exception(Resources.Messages.Login_BlockedUser); if (user.Role.RecordStatus == (byte)RecordStatus.Inactive) throw new Exception(Resources.Messages.Login_InactiveRole); var roleActions = new RoleActionRepository().GetByRoleID(user.RoleID); Session["UserID"] = user.ID; Session["UserName"] = user.UserName; Session["UserRole"] = user.RoleName; Session["RoleActions"] = roleActions; result = JsonResult(true, ""); } catch (Exception ex) { result = JsonResult(false, ex.Message); } return result; }
public UnitOfWork(SsoDbContext context) { _context = context; UserRepository = new UserRepository(_context); RoleRepository = new RoleRepository(_context); UserRoleRepository = new UserRoleRepository(_context); ActionRepository = new ActionRepository(_context); RoleActionRepository = new RoleActionRepository(_context); ApplicationRepository = new ApplicationRepository(_context); RoleApplicationRepository = new RoleApplicationRepository(_context); SecurityLevelRepository = new SecurityLevelRepository(_context); SecurityModeRepository = new SecurityModeRepository(_context); SecurityLevelModelRepository = new SecurityLevelModelRepository(_context); SettingRepository = new SettingRepository(_context); SessionRepository = new SessionRepository(_context); UserRestrictedIpRepository = new UserRestrictedIpRepository(_context); HardwareTokenCodeRepository = new HardwareTokenCodeRepository(_context); MobileVerificationCodeRepository = new MobileVerificationCodeRepository(_context); RoleGroupRepository = new RoleGroupRepository(_context); AuthenticationStepRepository = new AuthenticationStepRepository(_context); }
/// <summary> /// 查询是否有权限 /// </summary> /// <param name="lRoleId"></param> /// <param name="controllerName"></param> /// <param name="actionName"></param> /// <returns></returns> private bool GetRoleAction(List <int> lRoleId, string controllerName, string actionName) { MenuActionRepository menuActionRep = new MenuActionRepository(); string url = "/" + controllerName + "/" + actionName; if (!menuActionRep.Exist(m => m.ActionUrl == url)) { return(false); } int intMenuActionID = menuActionRep.Find(m => m.ActionUrl == url).MenuActionID; RoleActionRepository roleActionRep = new RoleActionRepository(); foreach (var roldID in lRoleId) { if (roleActionRep.Exist(r => r.MenuActionID == intMenuActionID && r.RoleID == roldID)) { return(true); } } return(false); }
private static int DeleteRecordsByControllerAction(Server.Models.Action action) { int ret = 0; if (null != action) { using (TransactionalDbClient tc = ionixFactory.CreateTransactionalDbClient()) { ActionRepository actionRepository = new ActionRepository(tc.Cmd); //RoleControllerAction Siliniyor. RoleActionRepository roleActionRepository = new RoleActionRepository(tc.Cmd); ret += roleActionRepository.DeleteByControllerActionIds(action.Id.ToSingleItemList()); //controllerAction Siliniyor. ret += actionRepository.Delete(action); tc.Commit(); } } return(ret); }
public string GetByID() { string result = ""; int id = Numerics.GetInt(Request["id"]); try { var role = new RoleRepository().GetByID(id); var roleActions = new RoleActionRepository().GetByRoleID(id); var js = new { ID = role.ID, Name = role.Name, RoleActions = roleActions, }; result = JsonConvert.SerializeObject(js); } catch (Exception ex) { result = ex.Message; } return result; }
private static int DeleteRecordsByControllerAction(Models.Action action) { int ret = 0; if (null != action) { using (TransactionalDbClient tc = DataFactory.CreateTransactionalDbClient()) { ActionRepository actionRepository = new ActionRepository(tc.Cmd); //RoleControllerAction Siliniyor. RoleActionRepository roleActionRepository = new RoleActionRepository(tc.Cmd); ret += roleActionRepository.DeleteByControllerActionIds(action.Id.ToSingleItemList()); //controllerAction Siliniyor. ret += actionRepository.Delete(action); tc.Commit(); } } return ret; }
private static int DeleteRecordsByController(Controller controller) { int ret = 0; using (TransactionalDbClient tc = DataFactory.CreateTransactionalDbClient()) { ControllerRepository controllerRepository = new ControllerRepository(tc.Cmd); ActionRepository actionRepository = new ActionRepository(tc.Cmd); List<Models.Action> controllerActions = actionRepository.SelectByControllerId(controller.Id).ToList(); if (!controllerActions.IsEmptyList()) { List<int> controllerActionIds = new List<int>(controllerActions.Count); controllerActions.ForEach((aa) => controllerActionIds.Add(aa.Id)); //RoleControllerAction Siliniyor. RoleActionRepository roleControllerActionRepository = new RoleActionRepository(tc.Cmd); ret += roleControllerActionRepository.DeleteByControllerActionIds(controllerActionIds); //controllerAction Siliniyor. ret += actionRepository.DeleteByControllerId(controller.Id); } //controller Siliniyor. ret += controllerRepository.Delete(controller); tc.Commit(); } return ret; }
// RadioButton button List< çalışmıyor.> //Reflection ile gelen ekrandan oluşan verilerin db ye yansıltılması. public int Save(IEnumerable<RoleControllerActionEntity> list) { int ret = 0; if (!list.IsEmptyList()) { //Öncelikle Her nekadar entity de Role name olsa bile tek bir role adı olmalı. O yüzden kontrol ediyoruz. HashSet<string> roleNames = new HashSet<string>(); HashSet<ControllerType> cts = new HashSet<ControllerType>(); list.ForEach((e) => { roleNames.Add(e.RoleName); cts.Add(e.Type); }); if (roleNames.Count != 1) throw new ArgumentException("RoleActionEntity List contains more than one role"); if (cts.Count != 1) throw new ArgumentException("RoleActionEntity List contains more than one ControlType(Api or Mvc)"); using (TransactionalDbClient tc = DataFactory.CreateTransactionalDbClient()) { RoleRepository roleRepository = new RoleRepository(tc.Cmd); ControllerRepository controllerRepository = new ControllerRepository(tc.Cmd); ActionRepository actionRepository = new ActionRepository(tc.Cmd); IndexedEntityList<Role> dbRoles = new IndexedEntityList<Role>(roleRepository.Select(), r => r.Name); IndexedEntityList<Controller> dbControllers = new IndexedEntityList<Controller>(controllerRepository.Select(), a => a.Name); IndexedEntityList<Models.Action> dbActions = new IndexedEntityList<Models.Action>(actionRepository.Select(), a => a.ControllerId, a => a.Name); List<RoleAction> dbEntityList = new List<RoleAction>(list.Count()); Role dbRole = null; foreach (RoleControllerActionEntity uiEntity in list)//Storage veritabanından geldi. { // Buradayız ama. controller den gelecek check edi,lmiş contooler ve action ları RoleControllerAction tablosuna yazmak. dbRole = dbRoles.Find(uiEntity.RoleName); if (null == dbRole) { dbRole = DataFactory.CreateEntity<Role>(); dbRole.Name = uiEntity.RoleName;//Yani db de yoksa bile eğer reflection ile gelmiş ise yani eklendi ise db ye de ekle. roleRepository.Insert(dbRole); dbRoles.Add(dbRole); // yeni db ye eklenen kayıt cache lenmiş dataya ekleniyor. } //Önceklikle Controller Denetlenmeli. Controller dbController = dbControllers.Find(uiEntity.ControllerName); if (null == dbController) { dbController = DataFactory.CreateEntity<Controller>(); dbController.Name = uiEntity.ControllerName; dbController.Type = (Byte)((Int32)uiEntity.Type); controllerRepository.Insert(dbController); dbControllers.Add(dbController); } Models.Action dbControllerAction = dbActions.Find(dbController.Id, uiEntity.ActionName); if (null == dbControllerAction)//Yani db de yoksa bile eğer reflection ile gelmiş ise yani eklendi ise db ye de ekle. { dbControllerAction = DataFactory.CreateEntity<Models.Action>(); dbControllerAction.Name = uiEntity.ActionName; dbControllerAction.ControllerId = dbController.Id; actionRepository.Insert(dbControllerAction); dbActions.Add(dbControllerAction); } RoleAction dbEntity = DataFactory.CreateEntity<RoleAction>(); dbEntity.ActionId = dbControllerAction.Id; dbEntity.RoleId = dbRole.Id; dbEntity.Enabled = uiEntity.Enabled; dbEntityList.Add(dbEntity); // else cascade silinecek. } if (dbRole == null) throw new InvalidOperationException("Role can not be null"); RoleActionRepository roleActionRepository = new RoleActionRepository(tc.Cmd); //Örneğin RoleControllerAction Tablosunun hepsi Silenebilir. SqlQuery deleteQuery = @"delete rca from RoleAction rca inner join Action ca on rca.ActionId=ca.Id inner join Controller c on ca.ControllerId = c.Id where c.Type=@0 and rca.RoleId=@1".ToQuery(cts.First().Cast<int>(), dbRole.Id);//Zaten tüm elemanlar aynı ControllerType' a sahip olmak zorunda. ret += tc.DataAccess.ExecuteNonQuery(deleteQuery); ret = roleActionRepository.BatchInsert(dbEntityList); tc.Commit(); } } return ret; }
public RoleActionController() { _ObjRoleActionRepository = new RoleActionRepository(); }
// RadioButton button List< çalışmıyor.> //Reflection ile gelen ekrandan oluşan verilerin db ye yansıltılması. public int Save(IEnumerable <RoleControllerActionEntity> list) { int ret = 0; if (!list.IsEmptyList()) { //Öncelikle Her nekadar entity de Role name olsa bile tek bir role adı olmalı. O yüzden kontrol ediyoruz. HashSet <string> roleNames = new HashSet <string>(); list.ForEach((e) => { roleNames.Add(e.RoleName); }); if (roleNames.Count != 1) { throw new ArgumentException("RoleActionEntity List contains more than one role"); } using (TransactionalDbClient tc = ionixFactory.CreateTransactionalDbClient()) { RoleRepository roleRepository = new RoleRepository(tc.Cmd); ControllerRepository controllerRepository = new ControllerRepository(tc.Cmd); ActionRepository actionRepository = new ActionRepository(tc.Cmd); IndexedEntityList <Role> dbRoles = IndexedEntityList <Role> .Create(r => r.Name); dbRoles.AddRange(roleRepository.Select()); IndexedEntityList <Controller> dbControllers = IndexedEntityList <Controller> .Create(a => a.Name); dbControllers.AddRange(controllerRepository.Select()); IndexedEntityList <Server.Models.Action> dbActions = IndexedEntityList <Server.Models.Action> .Create(a => a.ControllerId, a => a.Name); dbActions.AddRange(actionRepository.Select()); List <RoleAction> dbEntityList = new List <RoleAction>(list.Count()); Role dbRole = null; foreach (RoleControllerActionEntity uiEntity in list)//Storage veritabanından geldi. { // Buradayız ama. controller den gelecek check edi,lmiş contooler ve action ları RoleControllerAction tablosuna yazmak. dbRole = dbRoles.Find(uiEntity.RoleName); if (null == dbRole) { dbRole = ionixFactory.CreateEntity <Role>(); dbRole.Name = uiEntity.RoleName;//Yani db de yoksa bile eğer reflection ile gelmiş ise yani eklendi ise db ye de ekle. roleRepository.Insert(dbRole); dbRoles.Add(dbRole); // yeni db ye eklenen kayıt cache lenmiş dataya ekleniyor. } //Önceklikle Controller Denetlenmeli. Controller dbController = dbControllers.Find(uiEntity.ControllerName); if (null == dbController) { dbController = ionixFactory.CreateEntity <Controller>(); dbController.Name = uiEntity.ControllerName; controllerRepository.Insert(dbController); dbControllers.Add(dbController); } Server.Models.Action dbControllerAction = dbActions.Find(dbController.Id, uiEntity.ActionName); if (null == dbControllerAction)//Yani db de yoksa bile eğer reflection ile gelmiş ise yani eklendi ise db ye de ekle. { dbControllerAction = ionixFactory.CreateEntity <Server.Models.Action>(); dbControllerAction.Name = uiEntity.ActionName; dbControllerAction.ControllerId = dbController.Id; actionRepository.Insert(dbControllerAction); dbActions.Add(dbControllerAction); } RoleAction dbEntity = ionixFactory.CreateEntity <RoleAction>(); dbEntity.ActionId = dbControllerAction.Id; dbEntity.RoleId = dbRole.Id; dbEntity.Enabled = uiEntity.Enabled; dbEntityList.Add(dbEntity); // else cascade silinecek. } if (dbRole == null) { throw new InvalidOperationException("Role can not be null"); } RoleActionRepository roleActionRepository = new RoleActionRepository(tc.Cmd); //Örneğin RoleControllerAction Tablosunun hepsi Silenebilir. SqlQuery deleteQuery = @"delete from RoleAction where RoleId=@0".ToQuery(dbRole.Id); ret += tc.DataAccess.ExecuteNonQuery(deleteQuery); ret = roleActionRepository.BatchInsert(dbEntityList); tc.Commit(); } } return(ret); }