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)); }
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)); }
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); }
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); }
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); }