예제 #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)));
                }
            }
        }
예제 #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,
                Gender = r.Entity.Gender == null ? "" : BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "Gender", r.Entity.Gender)),
                Name = BlEntity.FormatFullName(r.Entity),
                Number = r.Entity.IdType == "M" ? r.Entity.IdNum : "",
                r.Entity.FullEnLongName,
                Level = r.Level == null ? "" : BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "EmployeeLevel", r.Level)),
                Status = r.Status == "A" ? "check colorGreen" : "close colorRed"
            }).ToList();


            //Convert display model into json data
            return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords));
        }
예제 #3
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));
        }
예제 #4
0
        public static string FormatFullName(Entity entity, bool withMilitaryId = false)
        {
            var toRet = string.Empty;

            //Title
            if (CheckEmpty.String(entity.Title) != "")
            {
                toRet = BlCode.LoadSingle(Constants.SystemUser, "Title", entity.Title).Value1 + " ";
            }

            //Full arabic name
            toRet += entity.FullArLongName;

            //Military number if exists
            if (withMilitaryId)
            {
                if (CheckEmpty.String(entity.IdType) != "" && CheckEmpty.String(entity.IdNum) != "")
                {
                    if (CheckEmpty.String(entity.IdType) == "M")
                    {
                        toRet += " " + entity.IdNum;
                    }
                }
            }

            return(toRet);
        }
예제 #5
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,
                Type = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "ErrorType", r.Type.ToString())),
                Severity = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "ErrorSeverity", r.Severity.ToString())),
                Source = r.Source ?? "",
                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));
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        public void ResetPassword(long userId, long toResetUserId)
        {
            using (var tran = new TransactionScope())
            {
                var defaultPassword = BlCode.LoadSingle(userId, "_System", "DefaultPassword").Value1;
                var toResetUser     = LoadSingle(toResetUserId);
                toResetUser.Password           = Cryptography.ComputeToHash(defaultPassword);
                toResetUser.MustChangePassword = true;

                BlLog.Log(userId, Module, "Password reset", "UserPasswordReset", new object[] { toResetUser.UserName });
                tran.Complete();
            }
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
        public static Address GetDefaultAddress(long userId, long pin, bool withFullAddress = false)
        {
            var predicate = PredicateBuilder.True <Address>();

            predicate = predicate.And(m => m.Entity.Pin == pin);
            predicate = predicate.And(m => m.Sequence == 1);

            var blAddress = new BlAddress();
            var toRet     = blAddress.LoadSearch(userId, predicate, 1).SingleOrDefault() ?? new Address()
            {
                Country  = "0",
                Province = "0",
                Caza     = "0",
                Region   = "",
                Street   = "",
                Building = "",
                Floor    = "0",
                Phone1   = "",
                Phone2   = "",
                Phone3   = "",
                Fax      = ""
            };

            if (withFullAddress)
            {
                //Set the full address
                toRet.FullAddress = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}-{9}-{10}",
                                                  BlCode.LoadSingle(userId, "Country", toRet.Country ?? "0").Value1,
                                                  BlCode.LoadSingle(userId, "Province", toRet.Province ?? "0").Value1,
                                                  BlCode.LoadSingle(userId, "Caza", toRet.Caza ?? "0").Value1,
                                                  toRet.Region,
                                                  toRet.Street,
                                                  toRet.Building,
                                                  BlCode.LoadSingle(userId, "Floor", toRet.Floor ?? "0").Value1,
                                                  toRet.Phone1,
                                                  toRet.Phone2,
                                                  toRet.Phone3,
                                                  toRet.Fax);
            }

            return(toRet);
        }
예제 #13
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,
                Language = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "Language", r.LanguageId.ToUiString())),
                Parent = BlCode.GetCodeByLanguage(user, BlCode.LoadSingle(userId, "DescriptionParent", r.Parent)),
                r.Code,
                r.Text
            }).ToList();


            //Convert display model into json data
            return(GridVm.FormatResult(res, user.PageSize, pageIndex, totalRecords));
        }
예제 #14
0
 public static int DefaultTimeOut()
 {
     return(Convert.ToInt32(BlCode.LoadSingle(Constants.SystemUser, "_System", "DefaultTimeOut").Value1));
 }
예제 #15
0
        public void Initiate(long userId)
        {
            //Make sure multilanguage directory exists
            var rootDirectory = Constants.GetAppRootDirectory(Constants.GetCallingAssemblyLocalPath()) + "io\\multiLanguage\\";

            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }

            //Get system languages
            var languages = BlCode.LoadSingle(userId, "_System", "SystemLanguages").Value1.Split(',');

            //Loop over each language and create its resource files
            foreach (var language in languages)
            {
                var files = new Dictionary <string, Dictionary <string, string> >();

                //Get language description
                var languageDesc = BlCode.LoadSingle(userId, "Language", language).Value1;

                //Get and make sure language directory exists
                var languageDirectory = rootDirectory + languageDesc + "\\";
                if (!Directory.Exists(languageDirectory))
                {
                    Directory.CreateDirectory(languageDirectory);
                }

                //Load language descriptions
                var predicate     = PredicateBuilder.True <Description>();
                var localLanguage = language;
                predicate = predicate.And(e => e.LanguageId == Convert.ToInt16(localLanguage));
                var blDescription = new BlDescription();
                var descriptions  = blDescription.LoadSearch(userId, predicate).ToList();

                //Clear resource cache
                foreach (var resource in descriptions.Select(d => d.Parent).Distinct())
                {
                    CacheHelper.Clear(string.Format("{0}_{1}", languageDesc, resource));
                }

                //Recreate the cache for server side uasge
                foreach (var description in descriptions)
                {
                    if (description.Parent == "")
                    {
                        description.Parent = "language";
                    }

                    if (!files.ContainsKey(description.Parent))
                    {
                        files.Add(description.Parent, new Dictionary <string, string>());
                    }

                    files[description.Parent].Add(description.Code, description.Text);
                    CacheHelper.Add(string.Format("{0}_{1}_{2}", languageDesc, description.Parent, description.Code), description.Text);
                }

                //Recreate the json files for client side usage
                foreach (var file in files)
                {
                    var ioFile = languageDirectory + file.Key + ".js";
                    if (!File.Exists(ioFile))
                    {
                        File.Create(ioFile).Close();
                    }
                    var json = JsonConvert.SerializeObject(file.Value);
                    File.WriteAllText(ioFile, json);
                }
            }
        }