Example #1
0
        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);
        }
Example #2
0
        // 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);
        }
Example #3
0
        public int SaveRoleControllerAction(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 (var db = ionixFactory.CreateTransactionalDbContext())
                {
                    IndexedEntityList <Role> dbRoles = IndexedEntityList <Role> .Create(r => r.Name);

                    dbRoles.AddRange(db.Roles.Select());

                    IndexedEntityList <Controller> dbControllers = IndexedEntityList <Controller> .Create(a => a.Name);

                    dbControllers.AddRange(db.Controllers.Select());

                    IndexedEntityList <Server.Models.Action> dbActions = IndexedEntityList <Server.Models.Action> .Create(a => a.ControllerId, a => a.Name);

                    dbActions.AddRange(db.Actions.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.

                            db.Roles.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;

                            db.Controllers.Insert(dbController);

                            dbControllers.Add(dbController);
                        }

                        Server.Models.Action dbControllerAction = dbActions.Find(dbController.ControllerId, 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.ControllerId;

                            db.Actions.Insert(dbControllerAction);

                            dbActions.Add(dbControllerAction);
                        }

                        RoleAction dbEntity = ionixFactory.CreateEntity <RoleAction>();
                        dbEntity.ActionId = dbControllerAction.ActionId;
                        dbEntity.RoleId   = dbRole.RoleId;
                        dbEntity.Enabled  = uiEntity.Enabled;

                        dbEntityList.Add(dbEntity);
                        // else cascade silinecek.
                    }
                    if (dbRole == null)
                    {
                        throw new InvalidOperationException("Role can not be null");
                    }

                    //Örneğin RoleControllerAction Tablosunun hepsi Silenebilir.

                    ret += db.ExecuteNonQuery("DELETE FROM role_action WHERE role_id=:0", dbRole.RoleId);

                    //ret = roleActionRepository.BatchInsert(dbEntityList); it works on sql server but not postgres when using transaction.

                    dbEntityList.ForEach(i => ret += db.RoleActions.Insert(i)); //this one also works on postgress.


                    db.Commit();
                }
            }

            return(ret);
        }