예제 #1
0
        public int Save(EmployeeModel obj)
        {
            CU_Employee oldObj  = new CU_Employee();
            CU_Employee oldObj2 = new CU_Employee();

            if (obj.ID > 0)
            {
                oldObj2 = GetByID((int)obj.ID);
                oldObj  = oldObj2.Clone();
            }

            // decrypt password to prevent double ecryption
            //    string decryptedPassword = DataProtection.Decrypt(obj.Password);
            //   if (!decryptedPassword.Contains("The input is not"))

            //    obj.Password = string.IsNullOrEmpty(obj.Password) ? null : contract_Extention.testDecrypt(obj.Password);
            if (string.IsNullOrEmpty(obj.Password) != null)
            {
                string strsalt = string.Empty;
                obj.Password = hashSaltProtection.GeneratePasswordHash(obj.Password, out strsalt);
                obj.Salt     = strsalt;
            }
            var data = Mapper.Map <EmployeeModel, CU_Employee>(obj);

            int?parentLogId = 0;

            if (obj.ID > 0)
            {
                oldObj2.Name     = data.Name;
                oldObj2.Mobile   = data.Mobile;
                oldObj2.IsActive = data.IsActive;

                _CU_EmployeeRepository.Save(oldObj2);
                _unitOfWork.Submit();
                parentLogId = _logService.Update(data.ID, DataServiceArabicResource.User, oldObj, oldObj2, obj.UserId.Value, obj.ActionName);
            }
            else
            {
                _CU_EmployeeRepository.Save(data);
                _unitOfWork.Submit();
                obj.ID = data.ID;

                parentLogId = _logService.Insert(data.ID, DataServiceArabicResource.User, obj, obj.UserId.Value, obj.ActionName.ToLower().Replace("add", "edit").Replace("0", data.ID.ToString()));
            }

            int?logId;

            if (obj.UserRoles != null)
            {
                new CU_Employee_RoleProgramService().Save(obj.UserRoles, data.ID, parentLogId, out logId, obj.UserId.Value, "AddEdit");
            }
            return((int)data.ID);
        }
예제 #2
0
        public bool SaveNewPassword(int userid, string newPassword, string userguid)
        {
            CU_Employee emp = _Employee.Get(x => x.ID == userid).First();
            //  emp.Password = DataProtection.Encrypt(newPassword);
            string strsalt = string.Empty;

            emp.Password = hashSaltProtection.GeneratePasswordHash(newPassword, out strsalt);
            emp.Salt     = strsalt;
            _Employee.Save(emp);
            _unitOfWork.Submit();
            _logService.ChangePassword(emp.ID);
            SetResetPasswordExpired(userguid);
            return(true);
        }
        /// <summary>
        /// handle many to many relationship between Employees and roles BLL and Log logic
        /// </summary>
        /// <param name="SelectedRolesIds"></param>
        /// <param name="EmployeeID"></param>
        /// <param name="parentId"></param>
        /// <param name="logId"></param>
        /// <returns></returns>
        public bool Save(List <int> SelectedRolesIds, int EmployeeID, int?parentId, out int?logId, int userId, string ActionName)
        {
            bool Return = false;

            List <CU_Employee_Role> exsistingRows = CU_Employee_RoleServiceList.Where(x => x.IdEmployee == EmployeeID).ToList();

            List <int> toBeAddedIds = SelectedRolesIds.Where(x => !exsistingRows.Exists(y => y.IdRole == x)).ToList();

            List <CU_Employee_Role> toBeRemovedRows = exsistingRows.Where(x => !SelectedRolesIds.Exists(y => x.IdRole == y)).ToList();

            List <CU_Employee_Role> toBeAddedRows = new List <CU_Employee_Role>();
            CU_Employee             EmployeeObj   = _EmployeeRepository.GetList().Where(x => x.ID == EmployeeID).FirstOrDefault();

            foreach (var item in toBeAddedIds)
            {
                CU_Employee_Role obj = new CU_Employee_Role()
                {
                    IdRole     = item,
                    IdEmployee = EmployeeID
                };
                toBeAddedRows.Add(obj);
            }

            if (toBeRemovedRows.Count > 0)
            {
                toBeRemovedRows.ForEach(d => _CU_Employee_RoleServiceRepository.Delete(d));
            }
            if (toBeAddedRows.Count > 0)
            {
                toBeAddedRows.ForEach(a => _CU_Employee_RoleServiceRepository.Save(a));
            }

            List <string> lstWillBeDeleted = toBeRemovedRows.Select(x => EmployeeObj.Name + DataServiceArabicResource.FromGroup + roleServiceObj.RolesList.Where(a => a.ID == x.IdRole).FirstOrDefault().Name).ToList <string>();

            //x.CU_Role.Name
            _unitOfWork.Submit();

            ActionName = ActionName + "?Id=" + EmployeeID;
            //logId = logServiceObj.Update(parentId, EmployeeID, "صلاحيات المستخدم " + EmployeeObj.Name,null, null,toBeAddedRows.Select(x => EmployeeObj.Name + " إلى مجموعة " + roleServiceObj.RolesList.Where(a => a.ID == x.IdRole).FirstOrDefault().Name).ToList<string>(),"EmployeeRoles", userId, ActionName);
            //logId = logServiceObj.Update(logId, EmployeeID, "صلاحيات المستخدم " + EmployeeObj.Name, lstWillBeDeleted, null,null, "EmployeeRoles", userId, ActionName);
            logId  = 0;
            Return = true;

            return(Return);
        }
예제 #4
0
        public void ChangePassword(int id, string NewpassWord)
        {
            CU_Employee emp = _Employee.Get(x => x.ID == id).First();
            //  emp.Password = DataProtection.Encrypt(NewpassWord);
            string strsalt = string.Empty;

            emp.Password = hashSaltProtection.GeneratePasswordHash(NewpassWord, out strsalt);
            emp.Salt     = strsalt;
            _Employee.Update(emp);
            _unitOfWork.Submit();

            CU_Employee beforUpdate = emp.Clone();

            if (emp != null)
            {
                _logService.ChangePassword(emp.ID);
            }
        }