Exemplo n.º 1
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));
        }
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 = BlUser.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,
                ModuleId = r.Module.Id,
                r.Action,
                Text = r.Text ?? "",
                User = r.UserId == 0 ? "" : BlUser.LoadSingle(r.UserId).UserName,
                branch = BlBranch.GetBranchName(user.Id, r.BranchId),
                LogDate = r.EntryDate.ToString(true)
            }).ToList();


            //Convert display model into json data
            return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords));
        }
Exemplo n.º 3
0
        public UserVm Init(long userId, long?id)
        {
            var callingUser = LoadSingle(userId);

            var toRet = new UserVm
            {
                Branches   = BlBranch.GetLov(userId, true).ToDictionary(i => i.value, i => i.label),
                Languages  = BlCode.LoadTable(userId, "Language", callingUser.LanguageId == (int)Enumerations.Languages.English ? "Value1" : "Value2"),
                PageSizes  = BlCode.LoadTable(userId, "PageSizes", callingUser.LanguageId == (int)Enumerations.Languages.English ? "Value1" : "Value2"),
                ActionMode = Enumerations.ActionMode.Add,
                User       = new User {
                    LanguageId = 1, PageSize = 10
                }
            };

            if (id != null)
            {
                var user = LoadSingle((long)id);
                user.Pin    = user.Entity == null ? user.Pin : user.Entity.Pin;
                user.Entity = null;
                //user.Branch = null;
                toRet.User      = user;
                toRet.Signature = BlCommon.GetSignature(toRet.User.EnteringUserId, toRet.User.EntryDate);
                //Get all roles and check user assigned ones
                var blRole = new BlRole();
                var roles  = blRole.LoadAll(userId).ToList();
                if (user.Roles != null)
                {
                    foreach (var role in user.Roles)
                    {
                        if (roles.Where(r => r.Id == role.Id).Any())
                        {
                            roles.Where(r => r.Id == role.Id).SingleOrDefault().IsActive = true;
                        }
                    }
                }
                toRet.UserRoles = new JavaScriptSerializer().Serialize((from r in roles
                                                                        select new TreeItemVm
                {
                    id = r.Id.ToUiString(),
                    parent = r.ParentRole == null ? "#" : r.ParentRole.Id.ToUiString(),
                    text = r.Code ?? "",
                    icon = "fa fa-users colorMain",
                    state = "{\"checked\": \"" + (r.IsActive ? "true" : "false") + "\"}",
                    li_attr = "{\"class\" : \"form-control-label\"}"
                }));
                //user.Roles = null;
                toRet.ActionMode = Enumerations.ActionMode.Edit;
            }

            return(toRet);
        }
Exemplo n.º 4
0
        public static string GetReceiptHeader(long branchId, int headerNum)
        {
            var branch = BlBranch.LoadSingle(Constants.SystemUser, branchId);

            var toRet = string.Empty;

            switch (branch.Id)
            {
            case 1:
            {
                if (headerNum == 2)
                {
                    toRet = BlCode.LoadSingle(Constants.SystemUser, "Receipt_1", "Header2").Value1;
                }                                                                                                               // "مصلحة الديوان"; }
                if (headerNum == 3)
                {
                    toRet = branch.Entity.ArFirstName;
                }
                break;
            }

            case 2:
            {
                if (headerNum == 2)
                {
                    toRet = BlCode.LoadSingle(Constants.SystemUser, "Receipt_2", "Header2").Value1;
                }                                                                                                               // "الفرع الفني"; }
                if (headerNum == 3)
                {
                    toRet = branch.Entity.ArFirstName;
                }
                break;
            }

            case 3:
            {
                if (headerNum == 2)
                {
                    toRet = BlCode.LoadSingle(Constants.SystemUser, "Receipt_3", "Header2").Value1;
                }                                                                                                               // "مصلحة الديوان"; }
                if (headerNum == 3)
                {
                    toRet = branch.Entity.ArFirstName;
                }
                break;
            }
            }
            return(toRet);
        }
Exemplo n.º 5
0
        public static List <DdlVm.DdlOption> GetLov(long userId, string operation, bool required, string relCode = "")
        {
            if (operation.ToUpper() == "CODETABLES")
            {
                return(GetLovTables(userId, required).ToList());
            }

            if (operation.ToUpper() == "BRANCHES")
            {
                return(BlBranch.GetLov(userId, required).ToList());
            }

            var user      = BlUser.LoadSingle(userId);
            var fieldName = user.LanguageId == 1 ? "Value1" : "Value2";

            var blCode    = new BlCode();
            var predicate = PredicateBuilder.True <Code>();

            predicate = predicate.And(p => p.TableName == operation);

            if (relCode != "")
            {
                predicate = predicate.And(p => p.RelCode == relCode);
            }

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

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

            var results = (from a in result.Where(m => m.Status)
                           orderby a.DisplayOrder ascending
                           select new DdlVm.DdlOption
            {
                value = a.CodeName,
                label = a.GetType().GetProperty(fieldName).GetValue(a, null).ToString()
            }).ToList();

            if (!required)
            {
                results.Insert(0, new DdlVm.DdlOption("...", ""));
            }

            return(results.ToList());
        }
Exemplo n.º 6
0
        public EventVm Init(long userId, long id)
        {
            //Get current user
            var user = BlUser.LoadSingle(userId);

            var eventLog = LoadSingle(userId, id);
            var toRet    = new EventVm
            {
                Module   = eventLog.Module.Id,
                Action   = eventLog.Action,
                Text     = eventLog.Text,
                UserName = BlUser.LoadSingle(eventLog.UserId).UserName,
                Branch   = BlBranch.GetBranchName(user.Id, eventLog.BranchId),
                Date     = eventLog.EntryDate.ToString(true)
            };

            return(toRet);
        }
Exemplo n.º 7
0
        public ErrorVm Init(long userId, long id)
        {
            //Get current user
            var user = BlUser.LoadSingle(userId);

            var error = LoadSingle(userId, id);
            var toRet = new ErrorVm
            {
                Type     = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "ErrorType", error.Type.ToUiString())),
                Severity = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "ErrorSeverity", error.Severity.ToUiString())),
                Source   = error.Source,
                Text     = error.Text,
                UserName = BlUser.LoadSingle(error.UserId).UserName,
                Branch   = BlBranch.GetBranchName(user.Id, error.BranchId),
                Date     = error.EntryDate.ToString(true)
            };

            return(toRet);
        }
Exemplo n.º 8
0
        public LoginVm Authenticate(LoginVm model)
        {
            var hashedPass = Cryptography.ComputeToHash(model.Password);

            if (hashedPass == null)
            {
                throw new BusinessException("InvalidLogin");
            }

            var userRepository = new UserRepository();
            var predicate      = PredicateBuilder.True <User>();

            predicate = predicate.And(u => u.UserName == model.Username);
            var users = userRepository.LoadSearch(predicate);

            //Check if any user have same password
            IStructuralEquatable eqa1 = hashedPass;
            var user = users.FirstOrDefault(u => eqa1.Equals(u.Password, StructuralComparisons.StructuralEqualityComparer));

            if (user == null)
            {
                throw new BusinessException("InvalidLogin");
            }

            //Check if user is active
            if (user.IsBlocked)
            {
                throw new BusinessException("UserInactive");
            }

            UpdateTicketValidity(user.Id);

            model.SecurityToken = Cryptography.Encrypt(JsonConvert.SerializeObject(user.Id), true);
            model.Password      = null;
            model.Language      = BlCode.LoadSingle(user.Id, "Language", user.LanguageId.ToUiString()).Value1;
            model.BranchId      = user.BranchId;
            model.BranchName    = BlBranch.GetBranchName(user.Id);
            model.CrossBranches = BlPermission.CanDo(user.Id, "BRANCH", "CrossBranches");
            model.PageSize      = user.PageSize;
            BlLog.Log(user.Id, Module, "LogIn", "UserSuccessfulLogin", new object[] { user.UserName });
            return(model);
        }
Exemplo n.º 9
0
        public MenuVm Init(long userId, long?id)
        {
            var toRet = new MenuVm
            {
                Branches = BlBranch.GetLov(userId).ToDictionary(i => i.value, i => i.label),
                Statuses = BlCode.LoadTable(userId, "Status"),
                Menu     = new Menu {
                    Status = true
                },
                ActionMode = Enumerations.ActionMode.Add
            };

            if (id != 0)
            {
                var menu = LoadSingle(userId, Convert.ToInt64(id));
                toRet.Menu       = menu;
                toRet.ActionMode = Enumerations.ActionMode.Edit;
            }

            return(toRet);
        }
Exemplo n.º 10
0
        public ModuleVm Init(long userId, string id)
        {
            var toRet = new ModuleVm
            {
                Branches = BlBranch.GetLov(userId).ToDictionary(i => i.value, i => i.label),
                Statuses = BlCode.LoadTable(userId, "Status"),
                Module   = new Module {
                    Status = "A"
                },
                ActionMode = Enumerations.ActionMode.Add
            };

            if (id != "null")
            {
                var module = LoadSingle(userId, id);
                toRet.Module = module;
                //module.User.Roles = null;
                //module.Author.Roles = null;
                toRet.Signature  = BlCommon.GetSignature(toRet.Module.UserId, toRet.Module.EntryDate);
                toRet.ActionMode = Enumerations.ActionMode.Edit;
            }

            return(toRet);
        }