public ActionResult PostCompanyRoleAction(string id, int roleID)
 {
     string[] str = id.Split(','); //Chk_CityController_Create_False,
     for (int i = 0; i < str.Length; i++)
     {
         string[]    info           = str[i].Split('_');
         string      controllerName = info[1];
         string      actionName     = info[2];
         bool        isAssigned     = Convert.ToBoolean(info[3]);
         ROLE_ACTION roleAction     = db.ROLE_ACTION.Where(ra => ra.ControllerName == controllerName && ra.ActionName == actionName && ra.RoleId == roleID).SingleOrDefault();
         if (roleAction == null) // new
         {
             roleAction                = new ROLE_ACTION();
             roleAction.RoleId         = roleID;
             roleAction.ControllerName = controllerName;
             roleAction.ActionName     = actionName;
             db.ROLE_ACTION.Add(roleAction);
         }
         else
         {
             db.ROLE_ACTION.Remove(roleAction);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
        // POST: /Role/Delete/5
        public ActionResult RoleActionDelete(int id)
        {
            ROLE_ACTION roleAction = db.ROLE_ACTION.Find(id);

            db.ROLE_ACTION.Remove(roleAction);
            db.SaveChanges();
            return(RedirectToAction("RoleAction", new { id = roleAction.RoleId }));
        }
 public ActionResult PostAssignViewAction(string id, int companyID)
 {
     result = new Result();
     try
     {
         string[] str = id.Split(','); //Chk_CityController_Create_False,
         for (int i = 0; i < str.Length; i++)
         {
             if (!String.IsNullOrEmpty(str[i]))
             {
                 string[] info = str[i].Split('_');
                 if (!String.IsNullOrEmpty(info[1]))
                 {
                     string roleName       = info[1];
                     string controllerName = info[2];
                     bool   isAssigned     = Convert.ToBoolean(info[3]);
                     var    roleID         = db.ROLEs.AsEnumerable().Where(x => x.RoleName == roleName && x.CompanyId == companyID).Select(x => x.RoleId).FirstOrDefault();
                     var    listAllAction  = BaseUtil.GetListAllActionByController(controllerName);
                     //var listController = BaseUtil.GetListController();
                     var roleaction = db.ROLE_ACTION.Where(ra => ra.ControllerName == controllerName && ra.RoleId == roleID).ToList();
                     if (roleaction.Count == 0) // new
                     {
                         foreach (var item in listAllAction)
                         {
                             ROLE_ACTION roleAction = new ROLE_ACTION();
                             roleAction.RoleId         = roleID;
                             roleAction.ControllerName = controllerName;
                             roleAction.ActionName     = item.Value;
                             db.ROLE_ACTION.Add(roleAction);
                         }
                     }
                     else
                     {
                         db.ROLE_ACTION.RemoveRange(roleaction);
                     }
                     db.SaveChanges();
                     Thread.Sleep(4000);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         result.MessageType = MessageType.Error;
         result.Message     = ex.Message;
     }
     return(RedirectToAction("Index", result));
 }