Exemplo n.º 1
0
        public string LoadAllForTree(long userId)
        {
            var userIsEditor = BlPermission.CanDo(userId, Module, "HelpCreator");
            var predicate    = PredicateBuilder.True <Help>();

            //Exclude empty if not editor
            if (!userIsEditor)
            {
                predicate = predicate.And(e => e.Text != "");
            }
            var roleTree = LoadSearch(userId, predicate);

            //Get security permissions
            var allowView   = BlPermission.CanDo(userId, Module, "View");
            var allowAdd    = BlPermission.CanDo(userId, Module, "Add");
            var allowEdit   = BlPermission.CanDo(userId, Module, "Edit");
            var allowDelete = BlPermission.CanDo(userId, Module, "Delete");

            //Create return object
            var toRet = new List <TreeItemVm>();

            //Create root node
            var rootNode = new Help {
                Id = 0
            };

            //Add root node
            toRet.AddRange(ConstructTreeNode(userId, rootNode.SingleItemAsEnumerable(), false, allowAdd, false, false));

            //Add menus
            toRet.AddRange(ConstructTreeNode(userId, roleTree.ToList(), allowView, allowAdd, allowEdit, allowDelete));

            return(new JavaScriptSerializer().Serialize(toRet));
        }
Exemplo n.º 2
0
 public override void OnEntry(MethodExecutionArgs args)
 {
     if (Module != null && Permission != null)
     {
         BlPermission.CanDo(Convert.ToInt64(args.Arguments[0]), Module, Permission);
     }
 }
Exemplo n.º 3
0
        public Help LoadSingle(long userId, string page, string ctrl)
        {
            var userIsEditor = BlPermission.CanDo(userId, Module, "HelpCreator");

            var predicate = PredicateBuilder.True <Help>();

            predicate = predicate.And(p => p.Page == page);
            predicate = predicate.And(p => p.Ctrl == ctrl);
            var toRet = LoadSearch(userId, predicate).SingleOrDefault();

            //If entry does not exist then create it
            if (toRet == null && userIsEditor)
            {
                using (var tran = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    var toCreate = new Help
                    {
                        Page         = page,
                        Ctrl         = ctrl,
                        EntryDate    = BlCommon.GetServerDateTime(),
                        UserId       = userId,
                        Title        = "",
                        Text         = "",
                        DisplayOrder = "ZZ"
                    };
                    var blHelp = new BlHelp();
                    toRet = blHelp.Create(userId, toCreate);

                    tran.Complete();
                }
            }

            //If entry is empty and user not editor then get parent
            if (toRet.Text == "" && ctrl != "" && !userIsEditor)
            {
                predicate = PredicateBuilder.True <Help>();
                predicate = predicate.And(p => p.Page == page);
                predicate = predicate.And(p => p.Ctrl == "");
                toRet     = LoadSearch(userId, predicate).SingleOrDefault();
            }

            return(toRet);
        }
Exemplo n.º 4
0
        public static List <DdlVm.DdlOption> GetLov(long userId, bool isMandatory = false)
        {
            var user           = BlUser.LoadSingle(userId);
            var canCrossBranch = BlPermission.CanDo(userId, Module, "CrossBranches");

            var blBranch  = new BlBranch();
            var predicate = PredicateBuilder.True <Branch>();

            predicate = predicate.And(p => p.Status == "A");

            //Retrieve only user branch if cannot cross branch
            if (!canCrossBranch)
            {
                predicate = predicate.And(p => p.Id == user.BranchId);
            }

            var result = blBranch.LoadSearch(userId, predicate).ToList();

            if (!result.Any())
            {
                return(null);
            }

            var results = (from a in result
                           orderby a.Name ascending
                           select new DdlVm.DdlOption
            {
                value = a.Id.ToUiString(),
                label = user.LanguageId == 1 ? a.Entity.FullEnShortName : a.Entity.FullArShortName
            }).ToList();

            //Add empty value if can cross branch
            if (canCrossBranch && !isMandatory)
            {
                results.Insert(0, new DdlVm.DdlOption("...", ""));
            }

            return(results.ToList());
        }