Example #1
0
 public ActionResult CreateOrUpdateAction(string id, AppActionViewModel model)
 {
     using (var context = new AppSecurityContext())
     {
         try
         {
             var action     = mapper.Map <AppAction>(model);
             var repository = new ActionRepository(context);
             if (id != null)
             {
                 repository.Update(action);
             }
             else
             {
                 repository.Insert(action);
             }
             context.SaveChanges();
             return(RedirectToAction("Actions"));
         }
         catch (Exception ex)
         {
             ViewBag.Error = ex.Message;
             return(View(model));
         }
     }
 }
        public static void SaveActions(Action action)
        {
            if (action.Id == null)
            {
                _actionRepository.Insert(action);
            }
            else
            {
                _actionRepository.Update(action);
            }

            _actionRepository.SaveChangesAsync();
        }
        // 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;
        }
Example #4
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);
        }
    private Neos.Data.Action SaveAction()
    {
        if (SessionManager.CurrentUser == null)
        {
            Common.RedirectToLoginPage(this);
            return null;
        }

        ActionRepository repo = new ActionRepository();
        Neos.Data.Action saveItem = GetAction();
        if (string.IsNullOrEmpty(Request.QueryString["ActionID"]))
        {
            //Insert new record
            repo.Insert(saveItem);
        }
        else
        {
            //Update the record.
            saveItem.ActionID = int.Parse(Request.QueryString["ActionID"]);
            repo.Update(saveItem);
        }
        if (chkExportToOutlook.Checked)
        {
            string message = Common.ExportActionToAppoinment(saveItem);
            string script1 = "<script type=\"text/javascript\">";
            script1 += " alert(\"" + message + "\")";
            script1 += " </script>";
            if (!this.ClientScript.IsClientScriptBlockRegistered("exportAction"))
                this.ClientScript.RegisterStartupScript(this.GetType(), "exportAction", script1);
        }

        return saveItem;
    }