Exemplo n.º 1
0
        private void PreSave(long userId, ref User toSave, Enumerations.ActionMode action, string userRoles = "")
        {
            if (action == Enumerations.ActionMode.Add)
            {
                var defaultPassword = BlCode.LoadSingle(userId, "_System", "DefaultPassword").Value1;
                toSave.Password           = Cryptography.ComputeToHash(defaultPassword);
                toSave.MustChangePassword = true;
                toSave.EntryDate          = BlCommon.GetServerDateTime();
                toSave.LastPasswordUpdate = toSave.EntryDate;
                //toSave.Branch = BlBranch.LoadSingle(userId, toSave.Branch.Id);
            }
            else if (action == Enumerations.ActionMode.Edit)
            {
            }
            toSave.EnteringUserId = userId;
            toSave.Entity         = BlEntity.LoadSingle(userId, toSave.Pin);
            if (CheckEmpty.String(userRoles) != "")
            {
                if (toSave.Roles == null)
                {
                    toSave.Roles = new List <Role>();
                }

                toSave.Roles.Clear();
                foreach (var roleId in userRoles.Split(','))
                {
                    toSave.Roles.Add(BlRole.LoadSingle(userId, Convert.ToInt64(roleId)));
                }
            }
        }
Exemplo n.º 2
0
        public GridResults LoadPaging(long userId, string search, int pageIndex, out long totalRecords, string sortColumnName = "", string sortOrderBy = "")
        {
            //Get current user
            var user = LoadSingle(userId);

            //Query paged data
            var results = LoadPaging(userId, CreateFilter(search), user.PageSize, pageIndex - 1, out totalRecords);

            //Convert results into display model
            var res = (from r in results
                       select new
            {
                r.Id,
                r.UserName,
                Name = BlEntity.FormatFullName(r.Entity),
                Language = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "Language", r.LanguageId.ToUiString())),
                r.PageSize,
                roles = string.Join(",", r.Roles.Select(ro => ro.Code)),
                Branch = BlBranch.GetBranchName(user.Id, r.BranchId),
                IsBlocked = r.IsBlocked ? "close colorRed" : "check colorGreen"
            }).ToList();


            //Convert display model into json data
            return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords));
        }