public EmployeeVm Init(long userId, long?id) { var user = BlUser.LoadSingle(userId); var toRet = new EmployeeVm { Branches = BlBranch.GetLov(userId, true).ToDictionary(i => i.value, i => i.label), Titles = BlCode.LoadTable(userId, "Title"), Genders = BlCode.LoadTable(userId, "Gender"), IdTypes = BlCode.LoadTable(userId, "IdType"), Maritals = BlCode.LoadTable(userId, "Marital"), Statuses = BlCode.LoadTable(userId, "Status"), Levels = BlCode.LoadTable(userId, "EmployeeLevel"), ActionMode = Enumerations.ActionMode.Add, Employee = new Employee { Status = "A", Entity = new Entity { BranchId = user.BranchId, Nationality = 422, Status = "A" }, Level = "0" } }; if (id != null) { var obj = LoadSingle(userId, Convert.ToInt64(id)); toRet.Employee = obj; toRet.ActionMode = Enumerations.ActionMode.Edit; toRet.Signature = BlCommon.GetSignature(toRet.Employee.UserId, toRet.Employee.EntryDate); } return(toRet); }
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))); } } }
public PermissionVm Init(long userId, long?id) { var toRet = new PermissionVm { Statuses = BlCode.LoadTable(userId, "PermissionStatus"), ActionMode = Enumerations.ActionMode.Add, Permission = new Permission { Status = "A", Module = new Module() } }; if (id != null) { var permission = LoadSingle(userId, Convert.ToInt64(id)); toRet.Permission = permission; //Create roles tree var blRole = new BlRole(); var roles = blRole.LoadForPermission(userId, permission.Module.Id, permission.Code); toRet.RolesTree = new JavaScriptSerializer().Serialize((from r in roles select new TreeItemVm { id = r.Id.ToUiString(), parent = r.ParentRole == null ? "#" : r.ParentRole.Id.ToString(), text = r.Code ?? "", icon = "fa fa-users colorMain", state = "{\"checked\": \"" + (r.IsActive ? "true" : "false") + "\"}", li_attr = "{\"class\" : \"form-control-label\"}" })); toRet.Signature = BlCommon.GetSignature(toRet.Permission.UserId, toRet.Permission.EntryDate); toRet.ActionMode = Enumerations.ActionMode.Edit; } return(toRet); }
public static User LoadSingle(long userId, bool notFromCache = false) { if (userId == 0) { return(null); } User toRet; if (!CacheHelper.Get(Module + "_" + userId.ToUiString(), out toRet) || notFromCache) { var predicate = PredicateBuilder.True <User>(); predicate = predicate.And(e => e.Id == userId); var userRepository = new UserRepository(); toRet = userRepository.LoadSearch(predicate).First(); if (toRet != null) { if (toRet.Roles.Where(r => r.Id == Constants.FullAdminRole).Any()) { toRet.IsFullPermission = true; } CacheHelper.Add(Module + "_" + toRet.Id.ToUiString(), toRet, BlCommon.DefaultTimeOut()); } else { //Force cash refresh for module entry CacheHelper.Clear(Module + "_" + userId.ToUiString()); } } return(toRet); }
private static void PreSave(long userId, ref Entity toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; }
private static void UpdateTicketValidity(long userId) { var defaultTimeOut = Convert.ToInt32(BlCode.LoadSingle(userId, "_System", "DefaultTimeOut").Value1); //BlLogError.LogError("BlUser.UpdateTicketValidity", "Key: " + Module + "_DateStamp_" + userId.ToUiString() +", Value: " + BlCommon.GetServerDateTime()); //BlLogError.LogError("BlUser.UpdateTicketValidity", "Key: " + Module + "_ValidTill_" + userId.ToUiString() + ", Value: " + BlCommon.GetServerDateTime().AddMinutes(defaultTimeOut)); //Increment ticket cached lifetime CacheHelper.Add(Module + "_DateStamp_" + userId.ToUiString(), BlCommon.GetServerDateTime(), defaultTimeOut); CacheHelper.Add(Module + "_ValidTill_" + userId.ToUiString(), BlCommon.GetServerDateTime().AddMinutes(defaultTimeOut), defaultTimeOut); }
public Menu LoadSingle(long userId, long pin) { Menu toRet; if (!CacheHelper.Get(Module + "_" + userId.ToUiString(), out toRet)) { toRet = _repository.LoadSingle(pin); CacheHelper.Add(Module + "_" + toRet.Id.ToUiString(), toRet, BlCommon.DefaultTimeOut()); } return(toRet); }
public UserVm ProfileSave(long userId, UserVm toEdit) { using (var tran = new TransactionScope()) { var user = LoadSingle(toEdit.User.Id, true); if (toEdit.ChangePassword) { if (!Cryptography.ComputeToHash(toEdit.OldPassword).SequenceEqual(user.Password)) { throw new BusinessException("WrongOldPassword"); } if (!Cryptography.ComputeToHash(toEdit.NewPassword).SequenceEqual(Cryptography.ComputeToHash(toEdit.ConfirmPassword))) { throw new BusinessException("NewPasswordDoesNotmatchConfirmation"); } user.LastPasswordUpdate = BlCommon.GetServerDateTime(); if (user.PasswordHistory != "") { var oldPasswordList = CheckEmpty.String(user.PasswordHistory).Split(','); foreach (var pass in oldPasswordList) { if (Cryptography.ComputeToHash(toEdit.NewPassword).SequenceEqual(Convert.FromBase64String(pass))) { throw new BusinessException("NewPasswordFrequentlyUsed"); } } } user.PasswordHistory += user.PasswordHistory == "" ? "" : ","; user.PasswordHistory += Convert.ToBase64String(user.Password); var historyLength = BlCode.LoadSingle(userId, "_System", "PasswordHistroyLength").Value1; if (user.PasswordHistory.Split(',').Length > Convert.ToInt32(historyLength)) { var newPasswordHistroy = user.PasswordHistory.Split(',').ToList(); newPasswordHistroy.RemoveAt(0); user.PasswordHistory = string.Join(",", newPasswordHistroy); } user.Password = Cryptography.ComputeToHash(toEdit.NewPassword); toEdit.ChangePassword = false; } user.UserName = toEdit.User.UserName; user.LanguageId = Convert.ToInt16(toEdit.User.LanguageId); user.PageSize = Convert.ToInt16(toEdit.User.PageSize); Edit(userId, user); //Force cash refresh for module entry CacheHelper.Clear(Module + "_" + user.Id.ToUiString()); BlLog.Log(userId, Module, "Profile change", "UserProfileModified", new object[] { user.UserName }); tran.Complete(); return(toEdit); } }
private static void PreSave(long userId, ref Document toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { //Save physical file under specific location var file = toSave.File; toSave.Path = SavePhysicalFile(userId, ref file, toSave.Name, toSave.Reference); toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; }
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); }
public Log Create(long userId, Log toAdd) { using (var tran = new TransactionScope()) { toAdd.UserId = userId; toAdd.BranchId = BlUser.LoadSingle(toAdd.UserId).BranchId; toAdd.EntryDate = BlCommon.GetServerDateTime(); var toRet = _repository.Create(toAdd); tran.Complete(); return(toRet); } }
public Address Create(long userId, Address toAdd) { using (var tran = new TransactionScope()) { toAdd.EntryDate = BlCommon.GetServerDateTime(); toAdd.UserId = userId; toAdd.Sequence = GetPinNextSequence(userId, toAdd.Entity.Pin); var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Create address", "AddressCreated", new object[] { toAdd.Sequence, toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) }); tran.Complete(); return(toRet); } }
public Employee Create(long userId, Employee toAdd) { using (var tran = new TransactionScope()) { toAdd.UserId = userId; toAdd.EntryDate = BlCommon.GetServerDateTime(); var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Create employee", "EmployeeCreated", new object[] { toAdd.Entity.Pin, BlEntity.FormatFullName(toAdd.Entity) }); tran.Complete(); return(toRet); } }
private static void PreSave(long userId, ref Comment toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); } else { var oldComment = LoadSingle(userId, toSave.Id); oldComment.Text = toSave.Text; toSave = oldComment; } toSave.UserId = userId; }
public UserVm ProfileInit(long userId) { var user = LoadSingle(userId, true); var toRet = new UserVm { User = user, Languages = BlCode.LoadTable(userId, "Language", user.LanguageId == (int)Enumerations.Languages.English ? "Value1" : "Value2"), PageSizes = BlCode.LoadTable(userId, "PageSizes", user.LanguageId == (int)Enumerations.Languages.English ? "Value1" : "Value2"), Signature = BlCommon.GetSignature(user.EnteringUserId, user.EntryDate), ActionMode = Enumerations.ActionMode.Edit }; return(toRet); }
public IEnumerable <string> LoadTables(long userId) { IEnumerable <string> toRet; if (!CacheHelper.Get(Module + "_TableNames", out toRet)) { var codeRepository = new CodeRepository(); toRet = codeRepository.LoadTables(); if (toRet != null) { CacheHelper.Add(Module + "_TableNames", toRet, BlCommon.DefaultTimeOut()); } } return(toRet); }
public static Module LoadSingle(long userId, string id) { Module toRet; if (!CacheHelper.Get(Module + "_" + id.ToUpper(), out toRet)) { var moduleRepository = new ModuleRepository(); toRet = moduleRepository.LoadSingle(id); if (toRet != null) { CacheHelper.Add(Module + "_" + toRet.Id, toRet, BlCommon.DefaultTimeOut()); } } return(toRet); }
public Address Edit(long userId, Address toEdit) { using (var tran = new TransactionScope()) { if (toEdit.EntryDate == DateTime.MinValue) { toEdit.EntryDate = BlCommon.GetServerDateTime(); } var toRet = _repository.Edit(toEdit); BlLog.Log(userId, Module, "Edit address", "AddressModified", new object[] { toEdit.Sequence, toEdit.Entity.Pin, BlEntity.FormatFullName(toEdit.Entity) }); tran.Complete(); return(toRet); } }
private void PreSave(long userId, ref Permission toSave, Enumerations.ActionMode action, string roles = "") { if (action == Enumerations.ActionMode.Add) { toSave.Module = BlModule.LoadSingle(userId, toSave.Module.Id); toSave.EntryDate = BlCommon.GetServerDateTime(); } toSave.UserId = userId; if (CheckEmpty.String(roles) != "") { toSave.Roles.Clear(); foreach (var roleId in roles.Split(',')) { toSave.Roles.Add(BlRole.LoadSingle(userId, Convert.ToInt64(roleId))); } } }
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); }
public static Role LoadSingle(long userId, long?id, bool notFromCache = false) { if (id == null) { return(null); } Role toRet; if (!CacheHelper.Get(Module + "_" + Convert.ToInt64(id).ToUiString(), out toRet) || notFromCache) { var roleRepository = new RoleRepository(); toRet = roleRepository.LoadSingle(Convert.ToInt64(id)); if (toRet != null) { CacheHelper.Add(Module + "_" + toRet.Id.ToUiString(), toRet, BlCommon.DefaultTimeOut()); } } return(toRet); }
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); }
private static void PreSave(long userId, ref Employee toSave, Enumerations.ActionMode action) { if (action == Enumerations.ActionMode.Add) { toSave.EntryDate = BlCommon.GetServerDateTime(); toSave.Entity.EntryDate = toSave.EntryDate; toSave.Entity.UserId = toSave.UserId; toSave.Entity.Status = toSave.Status; } else if (action == Enumerations.ActionMode.Edit) { //toSave.Entity = BlEntity.LoadSingle(userId, toSave.Entity.Pin); if (toSave.Entity.Status == "S") { //TODO:Check no goods are related to this employee } } toSave.Entity.NameIndex = NameIndex.GetNameIndex(userId, toSave.Entity.FirstName, toSave.Entity.FamilyName, toSave.Entity.FatherName); toSave.Entity.NameIndex += NameIndex.GetNameIndex(userId, toSave.Entity.ArFirstName, toSave.Entity.ArFamilyName, toSave.Entity.ArFatherName); BlArDict.SetArabicDict(userId, toSave.Entity.FirstName, toSave.Entity.ArFirstName); BlArDict.SetArabicDict(userId, toSave.Entity.FatherName, toSave.Entity.ArFatherName); BlArDict.SetArabicDict(userId, toSave.Entity.FamilyName, toSave.Entity.ArFamilyName); }
public static Dictionary <string, string> LoadTable(long userId, string tableName, string toRetColumn = "Value1", string relCode = "") { var user = BlUser.LoadSingle(userId); toRetColumn = (toRetColumn == "Value1" || CheckEmpty.String(toRetColumn) == "") ? user.LanguageId == 1 ? "Value1" : "Value2" : toRetColumn; List <Code> results; if (!CacheHelper.Get(Module + "_Table_" + tableName + "_" + relCode, out results)) { var codeRepository = new CodeRepository(); var predicate = PredicateBuilder.True <Code>(); predicate = predicate.And(p => p.TableName == tableName); predicate = predicate.And(p => p.Status); if (relCode != "") { predicate = predicate.And(p => p.RelCode == relCode); } results = codeRepository.LoadSearch(predicate); if (results != null) { CacheHelper.Add(Module + "_Table_" + tableName + "_" + relCode, results, BlCommon.DefaultTimeOut()); } } Dictionary <string, string> toRet = null; if (results != null) { toRet = results.ToDictionary(k => k.CodeName, v => v.GetType().GetProperty(toRetColumn).GetValue(v, null).ToString()); } return(toRet); }
public IEnumerable <Code> LoadPaging(long userId, Expression <Func <Code, bool> > predicate, int pageSize, int pageNum, out long totCount) { IEnumerable <Code> toRet; if (!CacheHelper.Get(Module + "_" + pageSize + "_" + pageNum + "_" + Evaluator.PartialEval(predicate), out toRet)) { toRet = _repository.LoadPaging(predicate, pageSize, pageNum, out totCount); CacheHelper.Add(Module + "_" + pageSize + "_" + pageNum + "_" + Evaluator.PartialEval(predicate), toRet, BlCommon.DefaultTimeOut()); CacheHelper.Add(Module + "_totCount_" + Evaluator.PartialEval(predicate), totCount, BlCommon.DefaultTimeOut()); } else { CacheHelper.Get(Module + "_totCount_" + Evaluator.PartialEval(predicate), out totCount); } return(toRet); }
public IEnumerable <Code> LoadSearch(long userId, Expression <Func <Code, bool> > predicate, int count = 0) { IEnumerable <Code> toRet; if (!CacheHelper.Get(Module + "_" + Evaluator.PartialEval(predicate), out toRet)) { toRet = _repository.LoadSearch(predicate, count); CacheHelper.Add(Module + "_" + Evaluator.PartialEval(predicate), toRet, BlCommon.DefaultTimeOut()); } return(toRet); }
public static Code LoadSingle(long userId, string tableName, string codeName, bool notFromCache = false) { var toRet = new Code { TableName = tableName, CodeName = codeName }; if (!CacheHelper.Get(Module + "_" + toRet.TableName + "_" + toRet.CodeName, out toRet) || notFromCache) { var codeRepository = new CodeRepository(); toRet = codeRepository.LoadSingle(tableName, codeName); if (toRet != null) { if (tableName == "_System" && codeName == "DefaultTimeOut") { CacheHelper.Add(Module + "_" + toRet.TableName + "_" + toRet.CodeName, toRet, Convert.ToInt32(toRet.Value1)); } else { CacheHelper.Add(Module + "_" + toRet.TableName + "_" + toRet.CodeName, toRet, BlCommon.DefaultTimeOut()); } } } return(toRet); }
private static string BuildMenuItem(User user, Menu menuItem, bool forEdit) { if (forEdit) { return(string.Format("<input type='radio' name='chkMenu' id='chkMenu' value='{0}'/>{1}", menuItem.Id, BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true))); } if (menuItem.Module == null && menuItem.Parent == null) { return(string.Format("<a href='#' {1}>{0} <span class='caret'></a>", BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true), menuItem.Details)); } if (menuItem.Module == null) { return(string.Format("<a href='#' {1}>{0} </a>", BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true), menuItem.Details)); } return(string.Format("<a href='../{1}' target='content'>{2}</a>", Constants.GetWebAppRootUrl(), CheckEmpty.String(menuItem.Module.Path) + "?ts=" + DateUtilities.GetDateStamp(BlCommon.GetServerDateTime(), true), BlDescription.GetDescription(Enumerations.DescriptionResources.Language, menuItem.DescriptionCode, user.LanguageId, true))); }
public long?Authorize(string token, string requestUri = "") { try { var userId = Cryptography.Decrypt(token, true); if (Convert.ToInt64(userId) == 0) { throw new BusinessException("InvalidTicket", "lblUser"); } //Validate ticket user var user = LoadSingle(Convert.ToInt64(userId)); if (user == null) { throw new BusinessException("InvalidTicket", "lblUser"); } //Validate ticket user status if (user.IsBlocked) { throw new BusinessException("UserInactive"); } //Validate ticket datestamp DateTime dateStamp; if (!CacheHelper.Get(Module + "_DateStamp_" + userId, out dateStamp)) { //BlLogError.LogError("BlUser.Authorize", "Datestamp empty"); throw new BusinessException("InvalidTicket", "lblDate"); } if (dateStamp > BlCommon.GetServerDateTime()) { //BlLogError.LogError("BlUser.Authorize", "datestamp less than current date"); throw new BusinessException("InvalidTicket", "lblDate"); } //Validate ticket validtill DateTime validTill; if (!CacheHelper.Get(Module + "_ValidTill_" + userId, out validTill)) { //BlLogError.LogError("BlUser.Authorize", "Valid till is empty"); throw new BusinessException("InvalidTicket", "lblDate"); } if (validTill < BlCommon.GetServerDateTime()) { //BlLogError.LogError("BlUser.Authorize", "Valid till less than current date"); throw new BusinessException("InvalidTicket", "lblDate"); } UpdateTicketValidity(user.Id); return(user.Id); } catch (Exception) { if (requestUri.ToUpper().Contains("LOGOUT")) { return(1); } } return(null); }