public JsonResult Save(PermissionViewModel input)
 {
     if (input.EntityId >0)
     {
         var permission = _permissionsService.GetPermission(input.EntityId);
         Operation operation = _authorizationRepository.GetOperationById(input.Item.Operation.EntityId);
         permission.Level = input.Item.Level;
         permission.Allow = input.Item.Allow;
         permission.Operation = operation;
         permission.Description = input.Item.Description;
         if(input.UserGroupId>0)
         {
             var usersGroup = _authorizationRepository.GetUsersGroupById(input.UserGroupId);
             permission.UsersGroup = usersGroup;
         }
         else if (input.UliId > 0)
         {
             var userLoginInfo = _repository.Find<UserLoginInfo>(input.UliId);
             permission.User = userLoginInfo;
         }
         _permissionsBuilderService.Save(permission);
     }
     else
     {
         if (input.Item.Allow)
         {
             if (input.UserGroupId > 0)
             {
                 var usersGroup = _authorizationRepository.GetUsersGroupById(input.UserGroupId);
                 _permissionsBuilderService.Allow(input.Item.Operation.EntityId).For(usersGroup).OnEverything().Level
                     (input.Item.Level).Description(input.Item.Description).Save();
             }
             else if (input.UliId > 0)
             {
                 var userLoginInfo = _repository.Find<UserLoginInfo>(input.UliId);
                 _permissionsBuilderService.Allow(input.Item.Operation.EntityId).For(userLoginInfo).OnEverything().
                     Level(input.Item.Level).Description(input.Item.Description).Save();
             }
         }
         else
         {
             if (input.UserGroupId > 0)
             {
                 var usersGroup = _authorizationRepository.GetUsersGroupById(input.UserGroupId);
                 _permissionsBuilderService.Deny(input.Item.Operation.EntityId).For(usersGroup).OnEverything().Level(
                     input.Item.Level).Description(input.Item.Description).Save();
             }
             else if (input.UliId > 0)
             {
                 var userLoginInfo = _repository.Find<UserLoginInfo>(input.UliId);
                 _permissionsBuilderService.Deny(input.Item.Operation.EntityId).For(userLoginInfo).OnEverything().
                     Level(input.Item.Level).Description(input.Item.Description).Save();
             }
         }
     }
     _repository.Commit();
     var notification = new Notification { Success = true, Message = CoreLocalizationKeys.SUCCESSFUL_SAVE.ToString() };
     return Json(notification,JsonRequestBehavior.AllowGet);
 }
 public ActionResult Display(PermissionViewModel input)
 {
     var permission = _permissionsService.GetPermission(input.EntityId);
     var model = new PermissionViewModel()
     {
         Item = permission
     };
     return View(model);
 }
 public ActionResult AddUpdate(PermissionViewModel input)
 {
     var permission = input.EntityId > 0 ? _permissionsService.GetPermission(input.EntityId) : new Permission();
     var model = new PermissionViewModel()
                                   {
                                       Item = permission,
                                       UserGroupId =input.ParentId,
                                       UliId = input.RootId
                                   };
     if (input.EntityId <= 0)
     {
         var allOperations = _authorizationRepository.GetAllOperations();
         var operations = _selectListItemService.CreateList(allOperations, x => x.Name, x => x.EntityId, true);
         model.OperationList = operations;
     }
     return View(model);
 }